[Version]
⦁ 2024.04.02 / [Algorithm / Programmers] 2019 카카오 개발자 겨울 인턴십 - 크레인 인형뽑기 게임
import java.util.*;
class Solution {
public int solution(int[][] board, int[] moves) {
// [0,0,0,0,0]
// [0,0,1,0,3]
// [0,2,5,0,1]
// [4,2,4,4,2]
// [3,5,1,3,1]
int answer = 0;
Stack<Integer> stack = new Stack<>();
for(int i = 0; i < moves.length; i++) {
int move = moves[i] - 1;
for(int j = 0; j < board.length; j++) {
if(board[j][move] == 0) {
continue;
}
if(stack.isEmpty()) {
stack.push(board[j][move]);
}else {
if(stack.peek() != board[j][move]) {
stack.push(board[j][move]);
}else {
stack.pop();
answer += 2;
}
}
board[j][move] = 0;
break;
}
}
return answer;
}
}
'Algorithm > 프로그래머스' 카테고리의 다른 글
[Algorithm / Programmers] 숫자의 표현 (0) | 2024.04.03 |
---|---|
[Algorithm / Programmers] 다음 큰 숫자 (0) | 2024.04.03 |
[Algorithm / Programmers] 2020 카카오 인턴십 키패드 누르기 (0) | 2024.04.02 |
[Algorithm / Programmers] 햄버거 만들기 (0) | 2024.04.02 |
[Algorithm / Programmers] [PCCE 기출문제] 9번 / 이웃한 칸 (0) | 2024.04.02 |