https://school.programmers.co.kr/learn/courses/30/lessons/64061
음 ~~ 스택이군
쉽게 구현했으나
원소 접근하는게 살짝 헷갈렷다면 실화가..?
#include <string>
#include <vector>
#include <iostream>
#include <stack>
using namespace std;
int solution(vector<vector<int>> board, vector<int> moves) {
int answer = 0;
stack<int> buckets;
for (auto& m : moves) {
for (int j = 0 ; j < board.size() ; j++ ) {
int doll = board[j][m-1];
if (doll == 0) continue;
else {
board[j][m-1] = 0;
if (buckets.empty()) buckets.push(doll);
else if (buckets.top() != doll) buckets.push(doll);
else {
buckets.pop();
answer += 2;
}
break;
}
}
}
return answer;
}