프로그래머스 완주하지 못한 선수 해시

2023. 10. 25. 16:21알고리즘

 

hash를 사용해서 쉽게 구현 가능한 문제이다.

 

#include <string>
#include <vector>
#include <algorithm>
#include <unordered_map>

using namespace std;

string solution(vector<string> participant, vector<string> completion) {
    string answer = "";
    unordered_map<string, int> m;
    for (int i = 0;i < participant.size();i++) {
        m[participant[i]]++;
    }
    for (int i = 0;i < completion.size();i++) {
        m[completion[i]]--;
    }
    for (auto it : m) {
        if (it.second != 0 ){
            answer += it.first;
        }
    }
    return answer;
}