Recent Posts
Notice
No Rules Rules
같은 숫자는 싫어 (feat. 프로그래머스, 12906번) 본문
728x90
반응형
같은 숫자는 싫어
https://school.programmers.co.kr/learn/courses/30/lessons/12906
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
반응형
// woohyeon.kim
// kim519620.tistory.com
#include <vector>
#include <iostream>
#include <set>
using namespace std;
vector<int> solution(vector<int> arr)
{
vector<int> answer;
answer.push_back(arr[0]);
for(auto idx = 1; idx < arr.size(); ++idx)
if(answer.back() != arr[idx])
answer.push_back(arr[idx]);
return answer;
}
// *&)*@*
answer의 가장 마지막값과 push할 대상이 동일하지 않을 경우에만 push_back을 수행합니다.
728x90
반응형
'생활 > 코테' 카테고리의 다른 글
전화번호 목록 (feat. 프로그래머스, 42577번) (0) | 2022.08.17 |
---|---|
최소직사각형 (feat. 프로그래머스, 86491번) (0) | 2022.08.17 |
가장 긴 증가하는 부분 수열 2 (feat. 백준, 12015번) (0) | 2022.08.17 |
K번째 수 (feat. 백준, 1300번) (0) | 2022.08.17 |
공유기 설치 (feat. 백준, 2110번) (0) | 2022.08.17 |
Comments