stack.peek()
이 stack.top()
인줄 알고 첨에 에러났었다 (𐨛 𐌅 ࠅ 𐨛 ㅠㅠ)🌝 정답 풀이
import java.util.*; import java.io.*; class Solution { public int solution(int[][] board, int[] moves) { int answer = 0; int x = board.length; int y = board[0].length; Stack<Integer> stack = new Stack<>(); for(int i=0;i<moves.length;i++){ int idx = moves[i]-1; for(int k=0;k<x;k++){ if(board[k][idx]>0){ if(!stack.isEmpty() && stack.peek()==board[k][idx]){ answer+=2; stack.pop(); } else{ stack.push(board[k][idx]); } board[k][idx] = 0; break; } } } return answer; } }