728x90
https://programmers.co.kr/learn/courses/30/lessons/64061?language=javascript
https://programmers.co.kr/learn/challenges
(여기서 타고 들어감)
https://typescript-kr.github.io/
function solution(board, moves) {
var answer = 0;
var stack = [];
moves.forEach((item, idx)=>{
var rowIdx = item-1;
console.log(board[rowIdx]);
var rowArr = board[rowIdx];
var rowArrCnt = rowArr.length;
if(rowArrCnt > 0) {
var result = board[rowIdx].pop();
if(result != 0) {
stack.push(result);
}
if(stack.length > 1) {
if(stack[stack.length-1] == stack[stack.length-2]) {
answer+=2;
stack.pop();
stack.pop();
}
}
}
});
return answer;
}
var 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]];
var moves = [1,5,3,5,1,2,1,4];
solution(board, moves);
728x90
댓글