https://programmers.co.kr/learn/courses/30/lessons/64061
import java.util.*;
class Solution {
public int solution(int[][] board, int[] moves) {
Stack<Integer> st = new Stack<>();
int cnt=0;
for(int t : moves){
int pick=-1;
for(int i=0;i<board.length;i++){
if(board[i][t-1]!=0){
pick = board[i][t-1];
board[i][t-1] = 0;
break;
}
}
if(!st.isEmpty()){
if(st.peek()==pick){
st.pop();
cnt += 2;
}
else if(pick!=-1){
st.push(pick);
}
}
else if(pick!=-1){
st.push(pick);
}
}
return cnt;
}
}