코딩테스트

프로그래머스 / 폰켓몬

murlocdev 2026. 7. 20. 21:48

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;
}