728x90
안녕하십니까. Eun🦆입니다.
![](https://t1.daumcdn.net/keditor/emoticon/niniz/large/025.gif)
풀이법 입니다.
코딩테스트 연습 - 제일 작은 수 제거하기
정수를 저장한 배열, arr 에서 가장 작은 수를 제거한 배열을 리턴하는 함수, solution을 완성해주세요. 단, 리턴하려는 배열이 빈 배열인 경우엔 배열에 -1을 채워 리턴하세요. 예를들어 arr이 [4,3,2,1
programmers.co.kr
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
vector<int> solution(vector<int> arr) {
vector<int> answer;
vector<int> same = arr;
int n = arr.size();
if(n==1)
{
answer.push_back(-1);
}
else
{
sort(same.rbegin(), same.rend());
printf("%d\n",same.back());
int b = same.back();
for(int i=0;i<n;i++)
{
if(b!=arr[i])
{
answer.push_back(arr[i]);
}
}
}
return answer;
}
네이버 블로그 리뉴얼입니다.
728x90
'개발 > Coding Test' 카테고리의 다른 글
[프로그래머스 C++ Lv1] 최대공약수와 최소공배수 (0) | 2022.06.06 |
---|---|
[프로그래머스 C++ Lv1] 짝수와 홀수 (0) | 2022.06.06 |
[프로그래머스 C++ Lv1] 정수 제곱근 판별 (0) | 2022.06.06 |
[프로그래머스 C++ Lv1] 자릿수 더하기 (0) | 2022.06.06 |
[프로그래머스 C++ Lv1] 약수의 합 (0) | 2022.06.06 |
댓글