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 b5fc3ec commit c6811d7Copy full SHA for c6811d7
valid-parentheses/hyer0705.ts
@@ -0,0 +1,20 @@
1
+function isValid(s: string): boolean {
2
+ const stack: string[] = [];
3
+
4
+ const matchMap = new Map<string, string>();
5
+ matchMap.set(")", "(");
6
+ matchMap.set("]", "[");
7
+ matchMap.set("}", "{");
8
9
+ for (const bracket of s) {
10
+ if (matchMap.has(bracket)) {
11
+ if (stack.length === 0 || matchMap.get(bracket) !== stack.pop()) {
12
+ return false;
13
+ }
14
+ } else {
15
+ stack.push(bracket);
16
17
18
19
+ return stack.length === 0;
20
+}
0 commit comments