[프로그래머스 / C++] 완주하지 못한 선수

Seulguo·2022년 7월 14일
0

Algorithm

목록 보기
75/185
post-thumbnail

🐣 문제

링크 : https://school.programmers.co.kr/learn/courses/30/lessons/42576


🐥 코드

#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(auto name : participant){
        hash[name]++;
    }
    
    for(auto name : completion){
        hash[name]--;
    }
    
    for(auto pair : hash){
        if(pair.second > 0){
            answer = pair.first;
            break;
        }
    }
    
    return answer;
}

0개의 댓글