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 fdf3120 commit e8c532dCopy full SHA for e8c532d
valid-parentheses/soobing.ts
@@ -0,0 +1,15 @@
1
+function isValid(s: string): boolean {
2
+ const result: string[] = [];
3
+ const open = ["(", "[", "{"];
4
+ const close = [")", "]", "}"];
5
+ for (let i = 0; i < s.length; i++) {
6
+ if (open.includes(s[i])) {
7
+ result.push(s[i]);
8
+ } else {
9
+ const index = close.findIndex((item) => item === s[i]);
10
+ const popedItem = result.pop();
11
+ if (popedItem !== open[index]) return false;
12
+ }
13
14
+ return result.length === 0;
15
+}
0 commit comments