Skip to content

Commit 26691e9

Browse files
authored
Merge pull request #474 from hyejjun/main
[ํ˜œ์ค€] Week6 ๋ฌธ์ œํ’€์ด
2 parents b21b003 + 9e5ef35 commit 26691e9

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

โ€Žvalid-parentheses/hyejjun.js

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* @param {string} s
3+
* @return {boolean}
4+
*/
5+
var isValid = function (s) {
6+
const stack = [];
7+
const map = {
8+
')': '(',
9+
'}': '{',
10+
']': '['
11+
};
12+
13+
for (let i = 0; i < s.length; i++) {
14+
const char = s[i];
15+
16+
if (char === '(' || char === '{' || char === '[') {
17+
stack.push(char);
18+
} else {
19+
if (stack.length === 0 || stack.pop() !== map[char]) {
20+
return false;
21+
}
22+
}
23+
}
24+
25+
return stack.length === 0;
26+
};

0 commit comments

Comments
ย (0)