Written by
java-style
on
on
[level1] 프로그래머스 - 크레인 인형뽑기 게임(JAVA)
[level1] 프로그래머스 - 크레인 인형뽑기 게임(JAVA)
728x90
[ 풀이 방법 ]
- 작성중..
[ 전체 코드 ]
import java.util.Stack; class Solution { public int solution(int[][] board, int[] moves) { int answer = 0; Stack stack = new Stack(); for (int i = 0; i < moves.length; i++) { int n = moves[i] - 1; // 인형 꺼낼 칸 for (int j = 0; j < board.length; j++) { if (board[j][n] != 0) { if (!stack.isEmpty() && stack.peek() == board[j][n]) { answer += 2; stack.pop(); } else { stack.add(board[j][n]); } board[j][n] = 0; break; } } } return answer; } }
728x90
from http://jisunshine.tistory.com/190 by ccl(A) rewrite - 2021-11-03 11:27:42