-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpostbox.js
More file actions
55 lines (46 loc) · 1.26 KB
/
postbox.js
File metadata and controls
55 lines (46 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/**
* @desc problem : 택배 상자
* @desc site : Programmers
* @desc level: 2
* @desc solution : Stack
*/
/**
* solution
* @param {array} orderList : 상자 순서 배열
*/
function solution(orderList) {
console.log('orderList', orderList);
const orderLength = orderList.length;
const temp = [];
let count = 1;
let answer = 0;
let order = orderList[answer];
while (order) {
console.log('loop', count, 'order', order, 'orderList', orderList, 'temp', temp);
console.log('answer! ', answer);
if (order === count) {
answer++;
order = orderList[answer];
count++;
continue;
}
if (order === temp[temp.length - 1]) {
answer++;
temp.pop();
order = orderList[answer];
continue;
} else if (order < temp[temp.length - 1]) {
break;
}
if (count <= orderLength) {
temp.push(count);
}
count++;
console.log('* answer > ', answer);
console.log('======================');
}
console.log('last! answer > ', answer);
console.log('======================');
return answer;
}
const answer = solution([2, 1, 4, 3, 6, 5, 8, 7, 10, 9]);