Skip to content

Commit

Permalink
合法的括号
Browse files Browse the repository at this point in the history
  • Loading branch information
rinwf committed Oct 24, 2018
1 parent 315c724 commit a2799b9
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions lc20. Valid Parentheses.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Solution:
def isValid(self, s):
"""
:type s: str
:rtype: bool
"""
d = {'(': ')', '[': ']', '{': '}'}
stack = []
for c in s:
if c in d:
stack.append(c)
else:
if len(stack) == 0:
return False
elif d[stack.pop()] != c:
return False
return len(stack) == 0

0 comments on commit a2799b9

Please sign in to comment.