Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution:
- def isValid(self, s: str) -> bool:
- """
- """
- stack = []
- for c in s:
- if c in ["(", "{", "["]:
- stack.append(c)
- else:
- if len(stack) == 0:
- return False
- elif c == ")" and stack[-1] != "(":
- return False
- elif c == "}" and stack[-1] != "{":
- return False
- elif c == "]" and stack[-1] != "[":
- return False
- else:
- stack.pop()
- return len(stack) == 0
Advertisement
Add Comment
Please, Sign In to add comment