[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 ...
随机推荐
- web服务器/应用服务器/http服务器/中间件
web服务器:只处理html静态页面不处理动态页面,如apache/nginx/iis等. 应用服务器:能处理html静态页面也能处理动态页面,如tomcat/weblogic/websphere/j ...
- 小程序使用wxParse解析html
转载至:http://blog.csdn.net/tang05709/article/details/54924675 这个是需要循环出显示的https://github.com/tonyzhan/c ...
- jQuery封装 写的的确不错 转载
扩展jQuery插件和方法的作用是非常强大的,它可以节省大量开发时间.这篇文章将概述jQuery插件开发的基本知识,最佳做法和常见的陷阱. 入门 编写一个jQuery插件开始于给jQuery.fn加入 ...
- ID基本操作(标尺,参考线,网格)5.11
参考线:标尺参考线,分栏参考线,出血参考线.在创建参考线之前确保标尺和参考线都可见.并且选中正确的跨页和页面作为目标, “版面”“创建参考线”可以输入数值创建参考线. 跨页参考线的创建:拖动参考线时鼠 ...
- linux系统管理 设置别名
查看和设定别名 'alias' 查看系统中所有的命令别名 [root@ssgao1987 ~]# alias alias cp='cp -i' alias l.='ls -d .* --color=a ...
- 解决ubuntu 14.04 “E: 无法获得锁 /var/lib/apt/lists/lock - open (11: 资源暂时不可用)”的问题
http://blog.csdn.net/nicolaskaiqi/article/details/39761757
- tomcat 线程数与 mysql 连接数综合调优
目前线上系统包含 数据收集+数据分析+中心服务,三个均为 tomcat,共用一个mysql服务. 由于tomcat最大线程数200 *3 =600,最大并发时,会有600个jdbc连接.当然这是极端情 ...
- vue安装与配置
直接引入 <script src="https://unpkg.com/vue"></script> 用npm安装 $ npm install vue ...
- iOS 设置不同环境下的配置 Debug Release 生产 测试 等等
其实这个问题大家都知道,但是一般都是清楚一些皮毛的东西,只能进行一些简单的应用.在这里详细说一下模式切换的使用. Xcode给我们自带了两种编译模式Release 和 Debug,通常情况下我们可以利 ...
- requests(第三方模块) 请求、登录、下载网页
import requests #http://docs.python-requests.org/en/latest/api/ 说明文档 ''' requests.request(method,ur ...