Open Soohan-Kim opened 3 weeks ago
class Solution:
def isValid(self, s: str) -> bool:
if len(s) % 2:
return 0
l = deque()
for c in s:
if c in ['(', '[', '{']:
l.append(c)
else:
if len(l) == 0:
return 0
if c == ')' and l[-1] == '(':
l.pop()
elif c == ']' and l[-1] == '[':
l.pop()
elif c == '}' and l[-1] == '{':
l.pop()
else:
return 0
if len(l):
return 0
return 1
https://leetcode.com/problems/valid-parentheses/description/