Skip to content

Commit

Permalink
이슈 #402에서 솔루션 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Nov 29, 2024
1 parent b15c478 commit 724a86e
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions Programmers/같은_숫자는_싫어.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <vector>
#include <iostream>
#include <stack>
#include <algorithm>

using namespace std;

vector<int> solution(vector<int> arr) {
stack<int> s;
vector<int> result;

s.push(arr[0]);
for (int num : arr) {
if (s.top() != num) {
s.push(num);
}
}

while (!s.empty()) {
result.push_back(s.top());
s.pop();
}

reverse(result.begin(), result.end());

return result;
}

0 comments on commit 724a86e

Please sign in to comment.