Skip to content

Commit 0c625f6

Browse files
committed
Update solution 020 [Python3]
1 parent dfacd96 commit 0c625f6

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

solution/020.Valid Parentheses/Solution.py

+23-1
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,26 @@ def isValid(self, s):
2121
pass
2222
else:
2323
f=False
24-
return f
24+
return f
25+
26+
class Solution():
27+
def isValid(self,s):
28+
"""
29+
:type s: str
30+
:rtype: bool
31+
"""
32+
left=['(','{','[']
33+
right={ ')':'(',
34+
']':'[',
35+
'}':'{' }
36+
stack=[]
37+
for i in s:
38+
if i in left:
39+
stack.append(i)
40+
elif stack and right[i] == stack.pop():
41+
continue
42+
else:
43+
return False
44+
if stack:
45+
return False
46+
return True

0 commit comments

Comments
 (0)