https://programmers.co.kr/learn/courses/30/lessons/64061
코딩테스트 연습 - 크레인 인형뽑기 게임
[[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]] [1,5,3,5,1,2,1,4] 4
programmers.co.kr
import java.util.Stack;
class Solution {
public int solution(int[][] board, int[] moves) {
int answer = 0;
Stack<Integer> bucket = new Stack<>();
for (int col : moves){
int colIndex = col - 1;
for (int rowIndex = 0; rowIndex < board.length; rowIndex++){
if (board[rowIndex][colIndex] != 0){
if (bucket.isEmpty() || bucket.peek() !=
board[rowIndex][colIndex]){
bucket.add(board[rowIndex][colIndex]);
}else{
bucket.pop();
answer += 2;
}
board[rowIndex][colIndex] = 0;
break;
}
}
}
return answer;
}
}
'Problem-solving > 프로그래머스' 카테고리의 다른 글
프로그래머스 - (2018 KAKAO BLIND RECRUITMENT) [1차]비밀지도 (Java) (0) | 2020.11.21 |
---|---|
프로그래머스 - (2020 카카오 인턴십) 키패드 누르기 (Java) (0) | 2020.11.21 |
프로그래머스 - (2018 KAKAO BLIND RECRUITMENT) [3차]자동완성 (Python3) (0) | 2020.09.03 |
프로그래머스 - (2019 KAKAO BLIND RECRUITMENT) 블록 게임 (Python3) (0) | 2020.09.02 |
프로그래머스 - (2019 KAKAO BLIND RECRUITMENT) 무지의 먹방 라이브 (Python3) (0) | 2020.09.01 |
댓글