We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 1e2f2b0 commit a4143c9Copy full SHA for a4143c9
1 file changed
JustDevRae/Stack/crane_claw_game.js
@@ -0,0 +1,23 @@
1
+function solution(board, moves) {
2
+ let answer = 0;
3
+ const stack = [];
4
+
5
+ for (let move of moves) {
6
+ for (let i = 0; i < board.length; i++) {
7
+ if (board[i][move - 1] !== 0) {
8
+ let doll = board[i][move - 1];
9
+ board[i][move - 1] = 0;
10
11
+ if (stack.length > 0 && stack[stack.length - 1] === doll) {
12
+ stack.pop();
13
+ answer += 2;
14
+ } else {
15
+ stack.push(doll);
16
+ }
17
+ break;
18
19
20
21
22
+ return answer;
23
+}
0 commit comments