Skip to content

Commit 1792d02

Browse files
committed
Feat: 연결 리스트, 스택, 큐 올바른 괄호(12909)
1 parent 29f0bda commit 1792d02

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

Diff for: 1주차/김유경/올바른 괄호.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
function solution(s){
2+
let answer = '';
3+
const stack = [];
4+
5+
for(let i=0, length = s.length; i < length; i++) {
6+
const word = s[i];
7+
if(i === 0) {
8+
stack.push(word);
9+
} else {
10+
if(stack[stack.length-1] === '(' && word === ')') {
11+
stack.pop();
12+
} else {
13+
stack.push(word);
14+
}
15+
}
16+
17+
}
18+
19+
answer = stack.length === 0;
20+
return answer;
21+
}

0 commit comments

Comments
 (0)