Skip to content

Commit 36baf25

Browse files
authored
Merge pull request #1 from prgrms-web-devcourse/1/김유경
1주차 김유경 문제 풀이
2 parents 51557c9 + 1792d02 commit 36baf25

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

Diff for: 1주차/김유경/같은 숫자는 싫어.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
function solution(arr) {
2+
const stack = [];
3+
4+
arr.forEach(number => {
5+
if(stack.length && stack[stack.length-1] === number) {
6+
stack.pop();
7+
}
8+
stack.push(number);
9+
})
10+
return stack;
11+
}

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)