1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | #include <vector> #include <iostream> using namespace std; vector<int> solution(vector<int> arr) { vector<int> answer; // 직전 숫자 임시 저장 int before = -1; for(int i = 0; i < arr.size(); i++){ if(arr[i] != before){ answer.push_back(arr[i]); before = arr[i]; } } return answer; } int main(void){ ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); vector<int> input{4,4,4,3,3}; vector<int> answer = solution(input); for(int i = 0; i < answer.size(); i++){ cout<<answer[i]<<" "; } return 0; } | cs |
'Problem-solving > 프로그래머스' 카테고리의 다른 글
프로그래머스 - 두 정수 사이의 합 (C++) (0) | 2020.03.04 |
---|---|
프로그래머스 - 나누어 떨어지는 숫자 배열 (C++) (0) | 2020.03.04 |
프로그래머스 - 체육복 (C++) (0) | 2020.02.29 |
프로그래머스 - 모의고사 (C++) (0) | 2020.02.28 |
프로그래머스 - 완주하지 못한 선수 (C++) (0) | 2020.02.28 |
댓글