-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3-crane.js
More file actions
40 lines (36 loc) · 768 Bytes
/
Copy path3-crane.js
File metadata and controls
40 lines (36 loc) · 768 Bytes
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
function solution({ board, moves }) {
const stack = [];
let burst = 0;
let tempItem;
moves.forEach(mItem => {
board.some(bItem => {
tempItem = bItem[mItem - 1];
if (tempItem) {
bItem[mItem - 1] = 0;
if (tempItem === stack[stack.length - 1]) {
burst += 2;
stack.pop();
} else {
stack.push(tempItem);
}
}
return tempItem;
})
})
console.log(stack, burst);
return burst;
}
// Execute Test
const exampleStrList = [
{
board: [
[0,0,0,0,0],
[0,0,1,0,3],
[0,2,5,0,1],
[4,2,4,4,2],
[3,5,1,3,1]
], //board 배열
moves: [1,5,3,5,1,2,1,4], //moves 배열
},
];
exampleStrList.forEach(exampleStr => solution(exampleStr));