snippets
filter:96 snippets
py-lc-validparens·python·leetcode
class Solution:
def isValid(self, s):
stack = []
pairs = {")": "(", "]": "[", "}": "{"}
for c in s:
if c in pairs:
if not stack or stack.pop() != pairs[c]:
return False
else:
stack.append(c)
return not stack
py-lc-validparens·python·leetcode
class Solution:
def isValid(self, s):
stack = []
pairs = {")": "(", "]": "[", "}": "{"}
for c in s:
if c in pairs:
if not stack or stack.pop() != pairs[c]:
return False
else:
stack.append(c)
return not stack