본문 바로가기

코딩 테스트/프로그래머스

[Level 1, C++] 완주하지 못한 선수

728x90
반응형

 

해쉬를 알아봐야해서 까다로웠던 문제이다.

 


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

string solution(vector<string> participant, vector<string> completion) {
    string answer = "";
    unordered_map<string, int> hash;
    for(string & s : participant)
    {
        hash[s]++;
    }
    for(string & s : completion)
    {
        hash[s]--;
    }
    for(auto & key : hash)
    {
        if(key.second != 0)
        {
            answer = key.first;
            break;
        }
    }
    return answer;
}
728x90
반응형