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