[Data Structure] An Algorithm for Matching Delimiters
Posted chiyeung
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[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 Interview Questions Data Structure Interview Questions
LeetCode Two Sum III - Data structure design
[Algorithm] JavaScript Graph Data Structure