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
나의 풀이
#include <string>
#include <vector>
#include <stack>
#include <iostream>
using namespace std;
int solution(vector<vector<int>> board, vector<int> moves) {
int answer = 0;
stack<int> buckets;
for (int n : moves) {
int top = 0;
for (; top < board.size(); top++) {
if (board[top][n - 1] != 0) break;
}
if (top < board.size()) {
if (!buckets.empty() && buckets.top() == board[top][n - 1]) {
answer += 2;
buckets.pop();
}
else {
buckets.push(board[top][n - 1]);
}
board[top][n - 1] = 0;
}
}
return answer;
}
'전공공부 > 코딩테스트' 카테고리의 다른 글
(c++) 프로그래머스 단체사진 찍기 (0) | 2022.01.11 |
---|---|
(c++) 프로그래머스 "카카오 프렌즈 컬러링북" (0) | 2022.01.11 |
(c++) 프로그래머스 키패드 누르기 (0) | 2022.01.06 |
(c++) 프로그래머스 숫자 문자열과 영단어 (0) | 2022.01.06 |
(c++) 프로그래머스 추석 트래픽 (0) | 2022.01.06 |