Created
October 9, 2019 22:42
-
-
Save motatoes/e96cb1d3b7456c3e00a85848f658f341 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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