본문 바로가기
[프로그래머스 C++]/LEVEL 1

[프로그래머스 C++] 제일 작은 수 제거하기

by AKI(JUNI) 2025. 4. 1.

◈ 문제 설명


◈ 문제 설명 링크

코딩테스트 연습 - 제일 작은 수 제거하기 | 프로그래머스 스쿨

 

프로그래머스

SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프

programmers.co.kr

 


◈ 작성 코드

#include <string>
#include <vector>
#include <algorithm>

using namespace std;

vector<int> solution(vector<int> arr) 
{
    vector<int> answer;
    vector<int> ace = arr;
    sort(arr.begin(), arr.end());
    
    if(arr.size() > 1)
    {
        for(int i = 0; i < ace.size(); i++)
        {
            for(int j = 1; j < arr.size(); j++)
            {
                if(ace[i] == arr[j])
                {
                    answer.push_back(ace[i]);
                }
            }
        }
    }
    else
    {
        answer.push_back(-1);
    }
    return answer;
}