class Solution:
def isValid(self, s: str) -> bool:
stack=[]
dic={'(':')','{':'}','[':']'}
for item in s:
if not stack or dic.get(item):
stack.append(item)
else:
if not dic.get(item) and item!=dic.get(stack.pop()):
return False
if stack:
return False
return True
LEETCODE 20. 有效的括号
最新推荐文章于 2024-11-04 12:20:00 发布