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.
2 parents 4fa8a1d + bfb7025 commit a2976d0Copy full SHA for a2976d0
valid-parentheses/Lustellz.ts
@@ -0,0 +1,26 @@
1
+// https://leetcode.com/problems/valid-parentheses
2
+// Rumtime: 6ms
3
+// Memory: 59.11MB
4
+
5
+function isValid(s: string): boolean {
6
+ let stack: string[] = [];
7
8
+ for (let i = 0; i < s.length; i++) {
9
+ if (["(", "{", "["].includes(s[i])) {
10
+ stack.push(s[i]);
11
+ } else {
12
+ switch (s[i]) {
13
+ case ")":
14
+ if (stack.pop() !== "(") return false;
15
+ break;
16
+ case "}":
17
+ if (stack.pop() !== "{") return false;
18
19
+ case "]":
20
+ if (stack.pop() !== "[") return false;
21
22
+ }
23
24
25
+ return stack.length === 0;
26
+}
0 commit comments