https://programmers.co.kr/learn/courses/30/lessons/64061
pop
할 땐 undifined
를 반환한다.answer += 2
function solution(board, moves) {
var answer = 0;
const st = [];
const map = board.map(_ => []);
board.forEach(b => {
b.forEach((v, i) => {
if (v !== 0)
map[i].unshift(v)
});
})
moves.forEach(m => {
const peek = map[m - 1].pop();
if (peek === undefined)
return;
if (peek === st[0]) {
st.shift();
answer += 2;
}
else
st.unshift(peek);
})
return answer;
}