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

phoenixKim·2021년 8월 12일
0

풀이 전략

  • 문제를 읽어보면 참가자 - 완주한 사람으로 이루어짐.
  • 낙오자가 단 한명만 있다고 한다.
  • 중복됨

=> unordered_map으로 풀이하면 된다고 생각함.
unordered_map<string, int>man;

소스코드

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

string solution(vector<string> participant, vector<string> completion) {
    string answer = "";
    
    unordered_map<string, int> man;
    
    for(const auto &i : participant)
        man[i]++;
    
    for(const auto &i : completion)
        man[i]--;
    
    for(const auto & i: man)
    {
        if(i.second == 1)
        {
            answer = i.first;
            break;
        }
    }
    
    return answer;
}

profile
🔥🔥🔥

0개의 댓글

관련 채용 정보