Skip to content

Commit aa40bb1

Browse files
committed
valid-parentheses solved
1 parent e59abd3 commit aa40bb1

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

valid-parentheses/hsskey.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* @param {string} s
3+
* @return {boolean}
4+
*/
5+
var isValid = function(s) {
6+
const stack = []
7+
8+
const pair = {
9+
')' : '(',
10+
'}' : '{',
11+
']' : '['
12+
}
13+
14+
for (let item of s) {
15+
// 여는 괄호
16+
if(item === '(' || item === '{' || item === '[') {
17+
stack.push(item)
18+
// stack길이가 0 or 닫는 괄호 케이스
19+
} else if (stack.length === 0 || stack.pop() !== pair[item]) {
20+
return false
21+
}
22+
}
23+
24+
return stack.length === 0
25+
};

0 commit comments

Comments
 (0)