[Data Structure] An Algorithm for Matching Delimiters
An important task when processing arithmetic expressions is to mach delimiters.
We can use Stack to solve this problem.
def is_matched(expr):
left='({['
right=')}]' S=ArrayStack() for c in expr:
if c in left:
S.push(c)
elif c in right:
if S.is_empty():
return False
if right.index(c)!=left.index(S.pop()):
return False
return S.is_empty()
[Data Structure] An Algorithm for Matching Delimiters的更多相关文章
- <Data Structure and Algorithm>排序算法
排序稳定:如果两个数相同,对他们进行的排序结果为他们的相对顺序不变.例如A={1,2,1,2,1}这里排序之后是A = {1,1,1,2,2} 稳定就是排序后第一个1就是排序前的第一个1,第二个1就是 ...
- [Algorithm] Heap data structure and heap sort algorithm
Source, git Heap is a data structure that can fundamentally change the performance of fairly common ...
- [Algorithm] Trie data structure
For example we have an array of words: [car, done, try, cat, trie, do] What is the best data structu ...
- [Algorithm] JavaScript Graph Data Structure
A graph is a data structure comprised of a set of nodes, also known as vertices, and a set of edges. ...
- [LeetCode] Add and Search Word - Data structure design 添加和查找单词-数据结构设计
Design a data structure that supports the following two operations: void addWord(word) bool search(w ...
- HDU5739 Fantasia(点双连通分量 + Block Forest Data Structure)
题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5739 Description Professor Zhang has an undirect ...
- hdu-5929 Basic Data Structure(双端队列+模拟)
题目链接: Basic Data Structure Time Limit: 7000/3500 MS (Java/Others) Memory Limit: 65536/65536 K (Ja ...
- CDOJ 483 Data Structure Problem DFS
Data Structure Problem Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/proble ...
- HDU 5929 Basic Data Structure 【模拟】 (2016CCPC东北地区大学生程序设计竞赛)
Basic Data Structure Time Limit: 7000/3500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Oth ...
随机推荐
- 微信小程序页面无法跳转
推荐网址:https://www.jianshu.com/p/e56b55334585 1.无法跳转原因分析 要跳转的路径在app.js里未注册过或路径写错 要跳转的路径是否位于TabBar中 页 ...
- python ctrl+c
#!/usr/bin/env pythonimport signalimport sysimport osdef signal_handler(signal, frame): print('You p ...
- python+ajaxFileUpload 无刷新上传文件
需要准备文件 http://pan.baidu.com/s/1bp4N3nL qqi0 html <script src="{% static 'js/jquery.js' %}& ...
- Linux 第一周作业
[](http://images2017.cnblogs.com/blog/1249774/201710/1249774-20171001234038872-10d31233192.pngd
- 【Java算法】冒泡排序
package suanfa; public class Maopao { public static void main(String[] args) { // TODO Auto-generate ...
- liunx文件操作 文件查看
文件的阅读命令 head 命令 head命令可以用来查看文件的开头部分,命令的格式是: head 文件名 默认设置,它只查看文件的前10行.但可以通过指定一个数字选项来改变要显示的行数,命令如下 he ...
- windows bat发布成服务
删除服务 删除名为"WINDOWS MANAGEMONT INSTALLER"的系统服务 sc delete "windows managemont Installer& ...
- Ubuntu下如何访问Windows磁盘?
有些同学的电脑原来是Windows系统的,但为了需要,又下载了一个Ubuntu系统,变成双系统的电脑. 但是,在Ubuntu下,Windows的磁盘是打不开的,用网盘或者U盘又是很不方便,所以ljn教 ...
- Java反射《三》获取属性
package com.study.reflect; import java.lang.reflect.Field; /** * 反射,获取属性 * @ClassName: FieldDemo * @ ...
- day20-正则表达式练习
import re from re import findall,search,S secret_code = 'hadkfalifexxIxxfasdjifja134xxlovexx23345sdf ...