C++:: 프로그래머스 < 제일 작은 수 제거하기 >

jahlee·2023년 8월 6일
0

프로그래머스_Lv.1

목록 보기
56/75
post-thumbnail

주어진 벡터에서 가장 작은수만 제거해서 반환해주면 되는 문제이다. 비어있다면 -1을 넣어서 반환.

#include <string>
#include <vector>
#include <algorithm>
using namespace std;

vector<int> solution(vector<int> arr) {
    arr.erase(min_element(arr.begin(), arr.end()));// 가장 작은 원소 삭제
    if (arr.empty()) return {-1};
    return arr;
}

0개의 댓글