๋ฌธ์
์ฝ๋
#include <string>
#include <vector>
#include <stack>
using namespace std;
int solution(vector<vector<int>> board, vector<int> moves) {
int answer = 0;
stack<int> basket;
for(int move:moves){
int pick_num = 0;
for(int i=0; i<board.size(); i++){
if(board[i][move-1]!=0){
pick_num = board[i][move-1];
board[i][move-1]=0;
break;
}
}
if(pick_num>0&&!basket.empty()){
if(basket.top()==pick_num){
basket.pop();
answer+=2;
}
else basket.push(pick_num);
}
else if(basket.empty()){
basket.push(pick_num);
}
}
return answer;
}
ํ์ด(19๋ถ)
ํฌ๊ฒ ๋ณต์กํ์ง๋ ์์์ต๋๋ค. move์์น์ depth๋ฅผ ๋ด๋ ค๊ฐ๋ฉด์ ์ธํ์ด ์์ ๋ ๋ฝ์ ๋ค์ ์ด์ stack์ top์ ์์ ๊ฒฝ์ฐ ํฐํธ๋ฆฌ๋ ์์ผ๋ก ๊ตฌํํ์ต๋๋ค.
'Algorithm ๐ง๐ปโ๐ป > ํ๋ก๊ทธ๋๋จธ์ค(Programmers)' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[c++] ํ๋ก๊ทธ๋๋จธ์ค - [1์ฐจ] ๋น๋ฐ ์ง๋(Level 1) (0) | 2022.04.13 |
---|---|
[c++] ํ๋ก๊ทธ๋๋จธ์ค - 3์ง๋ฒ ๋ค์ง๊ธฐ(Level 1) (0) | 2022.04.13 |
[c++] ํ๋ก๊ทธ๋๋จธ์ค - ์์ ๋ง๋ค๊ธฐ(Level 1) (0) | 2022.04.11 |
[c++] ํ๋ก๊ทธ๋๋จธ์ค - ํคํจ๋ ๋๋ฅด๊ธฐ(Level 1) (0) | 2022.04.10 |
[c++] ํ๋ก๊ทธ๋๋จธ์ค - ์ ๊ณ ๊ฒฐ๊ณผ ๋ฐ๊ธฐ(Level 1) (0) | 2022.04.08 |
[c++] ํ๋ก๊ทธ๋๋จธ์ค - ํ๋ ฌ ํ ๋๋ฆฌ ํ์ ํ๊ธฐ(Level 2) (0) | 2022.04.08 |
๋๊ธ