https://school.programmers.co.kr/learn/courses/30/lessons/1845
프로그래머스
SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
정렬은 필요없이 최소값 비교만 하면 되므로
unordered_map을 이용해 해결했다
더보기
#include <vector>
#include <unordered_map>
using namespace std;
int solution(vector<int> nums)
{
int answer = 0;
unordered_map<int,int> mMon;
for(int i = 0; i < nums.size(); i++)
{
mMon[nums[i]]++;
}
answer = min(mMon.size(),(nums.size()/2));
return answer;
}
'코딩테스트' 카테고리의 다른 글
| 프로그래머스 / 전화번호 목록 (0) | 2026.07.22 |
|---|---|
| 프로그래머스 / 완주하지 못한 선수 (0) | 2026.07.20 |
| 프로그래머스 / 네트워크 (0) | 2026.06.10 |
| 프로그래머스 / 게임 맵 최단거리 (0) | 2026.05.29 |
| 프로그래머스 / 타겟 넘버 (0) | 2026.05.29 |