Skip to content

Commit abbb28a

Browse files
committed
Feat: 배열, 연결 리스트, 스택, 큐 2문제
1 parent c0536f1 commit abbb28a

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
class Stack {
2+
constructor() {
3+
this.arr = [];
4+
this.index = -1;
5+
}
6+
7+
push(item) {
8+
this.arr[++this.index] = item;
9+
}
10+
11+
pop() {
12+
const temp = this.arr[this.index--];
13+
return temp;
14+
}
15+
16+
top() {
17+
return this.arr[this.index];
18+
}
19+
}
20+
21+
function solution(s) {
22+
var answer = true;
23+
24+
const stack = new Stack();
25+
26+
for (const char of s.split("")) {
27+
if (stack.top() === "(" && char === ")") {
28+
stack.pop();
29+
} else {
30+
stack.push(char);
31+
}
32+
}
33+
34+
return stack.index === -1;
35+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
function solution(arr) {
2+
var answer = [];
3+
4+
for (let i = 0; i < arr.length; i++) {
5+
if (arr[i] === answer[answer.length === 0 ? 0 : answer.length - 1]) {
6+
continue;
7+
} else {
8+
answer.push(arr[i]);
9+
}
10+
}
11+
12+
return answer;
13+
}

0 commit comments

Comments
 (0)