packageprogrammers.sully.week5;importjava.util.Stack;publicclass크레인_인형뽑기_Sully{publicstaticintsolution(int[][]board,int[]moves){intanswer=0;Stack<Integer>basket=newStack<>();basket.push(0);// 가장 아래 칸부터 쌓이고, 크레인은 가장 위 칸부터 뽑으니까for(intmove:moves){for(intj=0;j<board.length;j++){inttmp=board[j][move-1];if(tmp==0){continue;}if(basket.peek()==tmp){basket.pop();answer+=2;}else{basket.push(tmp);}board[j][move-1]=0;break;}}returnanswer;}}
Leave a comment