프로그래머스 - 크레인 인형뽑기 게임

  • 크레인 인형뽑기 게임
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
class Solution {


    public int solution(int[][] board, int[] moves) {

        List<Integer> list = new ArrayList<>();

        int count = 0;


        for (int move : moves) {

            for (int j = 0; j < board.length; j++) {
                if (board[j][move - 1] != 0) {
                    list.add(board[j][move - 1]);
                    if (list.size() >= 2 && Objects.equals(list.get(list.size() - 2), list.get(list.size() - 1))) {
                        list.remove(list.size() - 2);
                        list.remove(list.size() - 1);
                        count++;
                    }
                    board[j][move - 1] = 0;
                    break;
                }

            }

        }


        return count*2;
    }
}