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的更多相关文章

  1. <Data Structure and Algorithm>排序算法

    排序稳定:如果两个数相同,对他们进行的排序结果为他们的相对顺序不变.例如A={1,2,1,2,1}这里排序之后是A = {1,1,1,2,2} 稳定就是排序后第一个1就是排序前的第一个1,第二个1就是 ...

  2. [Algorithm] Heap data structure and heap sort algorithm

    Source, git Heap is a data structure that can fundamentally change the performance of fairly common ...

  3. [Algorithm] Trie data structure

    For example we have an array of words: [car, done, try, cat, trie, do] What is the best data structu ...

  4. [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. ...

  5. [LeetCode] Add and Search Word - Data structure design 添加和查找单词-数据结构设计

    Design a data structure that supports the following two operations: void addWord(word) bool search(w ...

  6. HDU5739 Fantasia(点双连通分量 + Block Forest Data Structure)

    题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5739 Description Professor Zhang has an undirect ...

  7. hdu-5929 Basic Data Structure(双端队列+模拟)

    题目链接: Basic Data Structure Time Limit: 7000/3500 MS (Java/Others)    Memory Limit: 65536/65536 K (Ja ...

  8. CDOJ 483 Data Structure Problem DFS

    Data Structure Problem Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/proble ...

  9. HDU 5929 Basic Data Structure 【模拟】 (2016CCPC东北地区大学生程序设计竞赛)

    Basic Data Structure Time Limit: 7000/3500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Oth ...

随机推荐

  1. PyCharm+QTDesigner+PyUIC使用教程

    我们在PyCharm安装配置Qt Designer+PyUIC教程中已配置好了PyCharm+QTDesigner+PyUIC环境 这里在此基上我们演示如何使用这些工具,编写一个图形界面程序: 程序主 ...

  2. MyBatis Spring整合配置映射接口类与映射xml文件

    本文转自http://blog.csdn.net/zht666/article/details/38706083 Spring整合MyBatis使用到了mybatis-spring,在配置mybati ...

  3. CentOS下安装Hbase

    1.安装JDK.https://www.cnblogs.com/zhi-leaf/p/10315125.html 2.下载Hbase.下载地址:https://hbase.apache.org/dow ...

  4. lombok @Slf4j注解

    背景知道有这么个东西,是因为项目中用到了@Slf4j注解. lombok库提供了一些注解来简化java代码 官网:http://projectlombok.org/ 查看lombok所有api:htt ...

  5. Win10系列:UWP界面布局基础12

    画刷 画刷(Brush)用于为图形元素填充颜色.在XAML中,画刷有许多属性,其中较常使用的是Fill属性和Stroke属性,Fill用于填充图形的背景色,而Stroke用于设置图形的线条颜色. 在实 ...

  6. Daily record-June

    June201. Dear, wake up! Seven o'clock now, it's time to get up. Wash your face and to have breakfast ...

  7. 如何快速成为一名Linux运维工程师

    如今的互联网,绝大多数的网站.服务.游戏均是跑在Linux上面的,虽说Linux发行版众多,只要玩熟了一种发行版,了解了Linux精髓.基本架构.设计原理,其他都是触类旁通的,千万不要在选择哪一发行版 ...

  8. day 69 权限的设置

    1.权限控制 1). 表结构的设置 2). 流程 1.登录 get: 通过中间件的白名单 re 获取到登录页面 post: 通过中间件的白名单,认证成功,保存权限信息, --ORM 去空的权限 去重 ...

  9. vue-6-事件处理

    <div id="example-2"> <button v-on:click="greet">Greet</button> ...

  10. 首次编译Java小程序

    public class helloworld { public static void main(string[] args) { system.out.println("hello wo ...