Created
July 19, 2018 13:38
-
-
Save luojiyin1987/3766a449555b658c6073c6cd9059347a to your computer and use it in GitHub Desktop.
#leetcode
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
| 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