Skip to content

Commit 714782a

Browse files
committed
week6: valid-parentheses
1 parent 4fb656c commit 714782a

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

valid-parentheses/reeseo3o.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const isValid = (s) => {
2+
const stack = [];
3+
const map = {
4+
"(": ")",
5+
"[": "]",
6+
"{": "}"
7+
};
8+
9+
for (const char of s) {
10+
if (map[char]) {
11+
console.log(char);
12+
stack.push(char);
13+
} else {
14+
if (stack.length === 0 || map[stack.pop()] !== char) {
15+
return false;
16+
}
17+
}
18+
}
19+
return stack.length === 0;
20+
}

0 commit comments

Comments
 (0)