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 c8051cb commit 27f07b2Copy full SHA for 27f07b2
valid-parentheses/i-mprovising.py
@@ -0,0 +1,24 @@
1
+"""
2
+Time complexity O(n)
3
+
4
+stack
5
6
+class Solution:
7
+ def isValid(self, s: str) -> bool:
8
+ open_brackets = ["(", "{", "["]
9
+ bracket_map = {"(":")", "{":"}", "[":"]"}
10
+ stack = []
11
+ for char in s:
12
+ if char in open_brackets:
13
+ stack.append(char)
14
+ continue
15
+ if not stack:
16
+ return False
17
+ open_b = stack.pop() # last in open bracket
18
+ if bracket_map[open_b] != char:
19
20
+ if stack:
21
22
+ return True
23
24
0 commit comments