Skip to content

Commit 3939144

Browse files
author
Eric
committed
105차 3번 문지풀이
1 parent a967730 commit 3939144

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
function solution(order) {
2+
const stack = [];
3+
let result = 0;
4+
let current = 1;
5+
6+
for (let i = 0; i < order.length; i++) {
7+
while (
8+
current <= order.length &&
9+
(stack.length === 0 || stack[stack.length - 1] !== order[i])
10+
) {
11+
stack.push(current);
12+
current++;
13+
}
14+
if (stack[stack.length - 1] === order[i]) {
15+
stack.pop();
16+
result++;
17+
} else {
18+
break;
19+
}
20+
}
21+
22+
return result;
23+
}
24+
25+
console.log(solution([4, 3, 1, 2, 5]));

0 commit comments

Comments
 (0)