Skip to content

Instantly share code, notes, and snippets.

@liondancer
Created January 4, 2017 06:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save liondancer/58bc4c0cbe142ab3d401dbddce8d68b2 to your computer and use it in GitHub Desktop.
Save liondancer/58bc4c0cbe142ab3d401dbddce8d68b2 to your computer and use it in GitHub Desktop.
def isValid(s):
"""
:type s: str
:rtype: bool
"""
if s:
if len(s) == 1:
return False
stack = []
d = {'[': ']', '(': ')', '{': '}'}
e = {']', '}', ')'}
for i in s:
if i in d:
stack.append(i)
elif i in e:
if len(stack) == 0 or d[stack.pop()] != i:
return False
else:
return False
return len(stack) == 0
return False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment