Skip to content

Commit 5af5fb3

Browse files
authored
Create 20-Valid-Parentheses.py
1 parent 5749a7f commit 5af5fb3

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

20-Valid-Parentheses.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution:
2+
def isValid(self, s: str) -> bool:
3+
Map = { ")":"(", "]":"[", "}":"{" }
4+
stack = []
5+
6+
for c in s:
7+
if c not in Map:
8+
stack.append(c)
9+
continue
10+
if not stack or stack[-1] != Map[c]:
11+
return False
12+
stack.pop()
13+
14+
return not stack

0 commit comments

Comments
 (0)