first iteration, passes 30/93
This commit is contained in:
parent
78f921fa39
commit
1c16e55844
@ -1,6 +1,25 @@
|
||||
def isValid(self, s):
|
||||
def isValid(s):
|
||||
"""
|
||||
:type s: str
|
||||
:rtype: bool
|
||||
"""
|
||||
|
||||
pervious = ""
|
||||
openBracket = ['(', '{', '[']
|
||||
bracketPairs = ['()', '{}', '[]']
|
||||
pairs = None
|
||||
|
||||
for x in s:
|
||||
if x in openBracket:
|
||||
previous = x
|
||||
else:
|
||||
# print(previous+x)
|
||||
if (previous+x) in bracketPairs:
|
||||
pairs = True
|
||||
else:
|
||||
return False
|
||||
return pairs
|
||||
|
||||
print(isValid("()"))
|
||||
print(isValid("()[]{}"))
|
||||
print(isValid("(]"))
|
||||
print(isValid("([)]"))
|
||||
Loading…
Reference in New Issue
Block a user