웅재의 코딩세상
[프로그래머스] 같은 숫자는 싫어 본문
- 풀이
#include <vector>
#include <iostream>
using namespace std;
vector<int> solution(vector<int> arr)
{
vector<int> answer;
answer.push_back(arr[0]);
for(int i=0; i<arr.size()-1; i++){
if(arr[i]!=arr[i+1]){
answer.push_back(arr[i+1]);
}
}
return answer;
}
반응형
'코딩테스트 > 프로그래머스 - LV 1' 카테고리의 다른 글
[프로그래머스] k번째수 (0) | 2024.02.13 |
---|---|
[프로그래머스] 가운데 글자 가져오기 (0) | 2024.02.09 |
[프로그래머스] 나누어 떨어지는 숫자 배열 (0) | 2024.02.09 |
[프로그래머스] 두 정수 사이의 합 (0) | 2024.02.09 |
[프로그래머스] 문자열 내 p와 y의 개수 (0) | 2024.02.09 |