Skip to content

Commit 0fbfd9f

Browse files
committed
105차 3번 문제풀이
1 parent 214ab95 commit 0fbfd9f

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
function solution(order) {
2+
const containerBelt = [];
3+
let now = 1;
4+
let count = 0;
5+
6+
for (let i = 0; i < order.length; i++) {
7+
const target = order[i];
8+
9+
console.log(target);
10+
11+
while (now <= order.length && now !== target) {
12+
containerBelt.push(now);
13+
now++;
14+
}
15+
console.log("belt:", containerBelt);
16+
17+
if (now === target) {
18+
count++;
19+
now++;
20+
} else if (containerBelt.length && containerBelt[0] === target) {
21+
containerBelt.shift();
22+
count++;
23+
} else {
24+
break;
25+
}
26+
27+
console.log("--------------");
28+
}
29+
30+
return count;
31+
}
32+
33+
console.log(solution([4, 3, 1, 2, 5])); // 출력: 2

0 commit comments

Comments
 (0)