Skip to content

Instantly share code, notes, and snippets.

@motatoes
Created October 9, 2019 22:42
Show Gist options
  • Save motatoes/e96cb1d3b7456c3e00a85848f658f341 to your computer and use it in GitHub Desktop.
Save motatoes/e96cb1d3b7456c3e00a85848f658f341 to your computer and use it in GitHub Desktop.
from collections import deque
class Solution:
def isValid(self, s: str) -> bool:
l = deque()
for i in range(len(s)):
if s[i] in "[({":
l.append(s[i])
elif s[i] in "})]":
if len(l) == 0:
return False
cc = l.pop()
if s[i] == "]" and cc != "[":
return False
if s[i] == ")" and cc != "(":
return False
if s[i] == "}" and cc != "{":
return False
return len(l) == 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment