stack = []
mapping = {
'(': ')',
'{': '}',
'[': ']'
}
for item in s:
if item in mapping.keys():
stack.append(mapping[item])
elif stack == [] or stack[-1] !=item:
return False
else:
stack.pop()
return True if stack==[] else False
力扣刷题20.有效括——python3
最新推荐文章于 2025-05-22 21:05:10 发布