# -*- coding: UTF-8 -*-
def bracket_match(s):
stack = []
left = ['(','[','{']
d = {
'(':')',
'[':']',
'{':'}'
}
for i in s:
if i in left:
stack.append(i)
else:
if len(stack) == 0:
print 'more right'
return False
elif d[stack[-1]] == i:
stack.pop()
else:
print 'left right not match'
return False
if len(stack):
print 'more left'
return False
else:
print 'no problem'
bracket_match('(()[])')
栈的应用:括号匹配
最新推荐文章于 2022-03-21 16:09:26 发布