- 난이도: Lv1
프로그래머스 링크: https://school.programmers.co.kr/learn/courses/30/lessons/64061
풀이 링크(GitHub): hayannn/CodingTest_Java/프로그래머스/1/크레인 인형뽑기
풀이 시간 : 49분
import java.util.*;
class Solution {
public int solution(int[][] board, int[] moves) {
int answer = 0;
Stack<Integer> basket = new Stack<>();
for (int move : moves) {
move -= 1;
for (int i = 0; i < board.length; i++) {
int doll = board[i][move];
if (doll != 0) {
board[i][move] = 0;
if (!basket.isEmpty() && basket.peek() == doll) {
basket.pop();
answer += 2;
} else {
basket.push(doll);
}
break;
}
}
}
return answer;
}
}