Skip to content

Commit 5008b80

Browse files
committed
20. Valid Parentheses Solution
1 parent 70c9b19 commit 5008b80

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

valid-parentheses/doh6077.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Use stack and Hashmap
2+
class Solution:
3+
def isValid(self, s: str) -> bool:
4+
match = {")": "(", "}": "{", "]": "["}
5+
stack = []
6+
7+
for ch in s:
8+
if ch in match:
9+
if stack and stack[-1] == match[ch]:
10+
stack.pop()
11+
else:
12+
return False
13+
else:
14+
stack.append(ch)
15+
return True if not stack else False
16+

0 commit comments

Comments
 (0)