반응형
https://programmers.co.kr/learn/courses/30/lessons/64061
import java.util.ArrayList;
public class Solution {
static ArrayList<Integer> bucket = new ArrayList();
public static int solution(int[][] board, int[] moves) {
int answer = 0;
for(int i=0; i<moves.length; i++) {
int y = moves[i]-1;
for(int j=0; j<board.length; j++) {
if(board[j][y] != 0) { // 크레인이 잡을 인형
if(!bucket.isEmpty() && bucket.get(bucket.size()-1) == board[j][y]) { // 바구니가 빈상태가 아니고 같은 인형이라면
bucket.remove(bucket.size()-1);
answer += 2;
} else {
bucket.add(board[j][y]); // 바구니에 인형을 넣는다.
}
board[j][y] = 0;
break;
}
}
}
return answer;
}
}
반응형
'알고리즘 > 카카오' 카테고리의 다른 글
비밀지도 (0) | 2020.05.26 |
---|---|
다트게임 (0) | 2020.05.24 |
실패율 (0) | 2020.05.15 |
[프로그래머스] 문자열 압축 (0) | 2020.04.10 |
[프로그래머스] 후보키 (0) | 2020.03.26 |