HTMLify
LeetCode - Valid Parentheses - Python
Views: 413 | Author: abh
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | class Solution: def isValid(self, s: str) -> bool: stack = [] m = { ')': '(', '}': '{', ']': '[', } for c in s: if c in ")}]" and (not stack or stack[-1] != m[c]): return False stack.append(c) if c in ")}]": stack.pop() stack.pop() if stack: return False return True |