class Solution:
def isValid(self, s: str) -> bool:
stack = []
for char in s:
if char == '(' or char == '[' or char == '{':
stack.append(char)
else:
if len(stack) == 0:
return False
else:
if char == ')':
if stack[-1] == '(':
stack.pop(-1)
else:
return False
elif char == ']':
if stack[-1] == '[':
stack.pop(-1)
else:
return False
elif char == '}':
if stack[-1] == '{':
stack.pop(-1)
else:
return False
if len(stack) == 0:
return True
else:
return False
01-06
606
11-28
424
10-10
508
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交