쉬운 문제였다.
N / 2를 저장해 두었다가, nums의 중복을 제거한 후, nums의 길이와 N / 2 중 큰 것을 return 해주면 되는 문제이다.
#include <vector>
#include <algorithm>
using namespace std;
int solution(vector<int> nums)
{
int answer = nums.size() / 2;
sort(nums.begin(), nums.end());
nums.erase(unique(nums.begin(), nums.end()), nums.end());
if (answer > nums.size())
answer = nums.size();
return answer;
}'Coding_Test 연습 > Programmers' 카테고리의 다른 글
| [프로그래머스] (C++) LV1 약수의 개수와 덧셈 (0) | 2022.04.18 |
|---|---|
| [프로그래머스] (C++) LV1 실패율 (0) | 2022.04.17 |
| [프로그래머스] (C++) LV1 체육복 (0) | 2022.04.15 |
| [프로그래머스] (C++) LV1 모의고사 (0) | 2022.04.14 |
| [프로그래머스] (C++) LV1 K번째수 (0) | 2022.04.14 |