Skip to content

Commit 1e89b4b

Browse files
committed
add solution: valid-parentheses
1 parent 6b7b619 commit 1e89b4b

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

valid-parentheses/yihyun-kim1.js

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

0 commit comments

Comments
 (0)