๐ ์๊ณ ๋ฆฌ์ฆ/Programmers
[C++/PGS] Lv.1 : ํฌ๋ ์ธ ์ธํ๋ฝ๊ธฐ ๊ฒ์(2019 ์นด์นด์ค)
xxilliant
2025. 6. 18. 20:47
728x90
๋ฐ์ํ
https://school.programmers.co.kr/learn/courses/30/lessons/64061
ํ๋ก๊ทธ๋๋จธ์ค
SW๊ฐ๋ฐ์๋ฅผ ์ํ ํ๊ฐ, ๊ต์ก์ Total Solution์ ์ ๊ณตํ๋ ๊ฐ๋ฐ์ ์ฑ์ฅ์ ์ํ ๋ฒ ์ด์ค์บ ํ
programmers.co.kr
ํ๋ก๊ทธ๋๋จธ์ค ๋ ๋ฒจ 1
์คํ์ ํ์ฉํ๋ฉด ๊ฐ๋จํ๊ฒ ํด๊ฒฐํ ์ ์๋ค!
๋์ ํ์ด
#include <string>
#include <vector>
#include <stack>
#include <iostream>
using namespace std;
int solution(vector<vector<int>> board, vector<int> moves) {
int answer = 0;
int n = board.size();
stack<int> st;
for(int num: moves){
int move = num - 1;
int get = 0;
for(int i=0; i<n; ++i){
if(board[i][move] != 0){
get = board[i][move];
board[i][move] = 0;
if(st.empty() || st.top() != get) st.push(get);
else if(!st.empty() && st.top() == get) {
answer+=2;
st.pop();
}
break;
}
}
}
return answer;
}
728x90
๋ฐ์ํ