Skip to content

Instantly share code, notes, and snippets.

@luojiyin1987
Created July 19, 2018 13:38
Show Gist options
  • Save luojiyin1987/3766a449555b658c6073c6cd9059347a to your computer and use it in GitHub Desktop.
Save luojiyin1987/3766a449555b658c6073c6cd9059347a to your computer and use it in GitHub Desktop.
#leetcode
class Solution:
def isValid(self, s):
"""
:type s: str
:rtype: bool
"""
stack, lookup = [], {"(": ")", "{": "}", "[": "]"}
for par in s:
if par in lookup:
stack.append(par)
elif len(stack) == 0 or lookup[stack.pop()] != par:
return False
return len(stack) == 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment