function solution(board, moves) {
var answer = 0;
var result = [];
for(const e of moves)
{
var floor = e - 1;
for(var i =0; i< board.length; i++)
{
var data = board[i][floor];
if (data !== 0)
{
if (result.length === 0)
{
result.push(data);
}
else
{
var trg = result.pop();
if (trg === data)
{
answer += 2
}
else
{
result.push(trg);
result.push(data);
}
}
board[i][floor] = 0;
break
}
}
}
return answer;
}
'๐ฏ CodingTest > Programmers' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Programmers] (Javascript) [1์ฐจ] ๋น๋ฐ์ง๋ (0) | 2022.04.21 |
---|---|
[Programmers] (Javascript) ์คํจ์จ (0) | 2022.04.21 |
[Programmers] (Javascript) ํคํจ๋ ๋๋ฅด๊ธฐ (0) | 2022.04.21 |
[Programmers] (Javascript) ์ซ์ ๋ฌธ์์ด๊ณผ ์๋จ์ด (0) | 2022.04.21 |
[Programmers] (Javascript) ์ ๊ท์์ด๋ ์ถ์ฒ (0) | 2022.04.21 |