-
728x90
[ 풀이 방법 ]
- 작성중..
[ 전체 코드 ]
import java.util.Stack;class Solution {public int solution(int[][] board, int[] moves) {int answer = 0;Stack<Integer> stack = new Stack<Integer>();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;}}데롱디롱희희.. (๑′ᴗ‵๑)
'알고리즘 풀이 > 프로그래머스' 카테고리의 다른 글
[level1] 프로그래머스 - 나머지가 1이 되는 수 찾기(JAVA) (0) 2021.11.03 [level1] 프로그래머스 - 없는 숫자 더하기(JAVA) (0) 2021.10.10 [level1] 프로그래머스 - 최소직사각형(JAVA) (0) 2021.10.10 [level2] 프로그래머스 - 게임 맵 최단거리(JAVA) (0) 2021.09.29 [level2] 프로그래머스 - 가장 큰 수(JAVA) (0) 2021.09.20