We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 43d392f commit 20baed8Copy full SHA for 20baed8
20_valid-parentheses.py
@@ -0,0 +1,25 @@
1
+class Solution:
2
+ def isValid(self, s: str) -> bool:
3
+ stack = []
4
+ parentheses_open = {
5
+ "(": ")",
6
+ "{": "}",
7
+ "[": "]"
8
+ }
9
+
10
+ parentheses_close = {
11
+ ")": "(",
12
+ "}": "{",
13
+ "]": "["
14
15
16
+ for c in s:
17
+ if parentheses_open.get(c) != None:
18
+ stack.append(c)
19
+ continue
20
+ if parentheses_close.get(c) != None:
21
+ if len(stack) > 0 and stack[-1] == parentheses_close.get(c):
22
+ stack.pop()
23
+ else:
24
+ return False
25
+ return True if len(stack) == 0 else False
0 commit comments