프로그래머스 크레인 인형뽑기 게임
-
Level1) 크레인 인형뽑기 게임PS/programmers 2020. 9. 11. 16:45
import java.util.Stack; class Solution { public int solution(int[][] board, int[] moves) { int answer = 0; Stack basket = new Stack(); for (int move : moves) { for (int i = 0; i < board.length; i++) { if (board[i][move-1] != 0) { if (basket.isEmpty() || basket.peek() != board[i][move-1]) { basket.push(board[i][move-1]); } else if (basket.peek() == board[i][move-1]) { basket.pop(); answer += 2; }..