first iteration, passes 30/93

This commit is contained in:
Jacob Delgado 2023-07-24 22:44:11 -07:00
parent 78f921fa39
commit 1c16e55844

View File

@ -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("([)]"))