크레인 인형뽑기 게임

limuubin·2022년 3월 9일
0
function solution(board, moves) {
    let cnt =0
    let box=[]
    let arr= Array.from(Array(board.length), () => new Array(board.length).fill(null))

    for(let i =0; i<board.length; i++){
        for(let j =0; j<board.length; j++){
            arr[j][board.length-1-i]=board[i][j]
        }
    }
    arr.map((el)=>{
        el.reverse()
    })

    for(let i = 0 ; i < moves.length; i++){
        for(let j = 0; j<board.length; j++){
            let leng = box.length-1
            if(arr[moves[i]-1][j] !==0){
                if(box[leng]===arr[moves[i]-1][j]){
                    cnt++
                    box.pop()       
                }
                else(
                    box.push(arr[moves[i]-1][j])
                    )
                    arr[moves[i]-1][j]=0   
                    break;
            }
        }
    }

return cnt*2
}

0개의 댓글