euisblue
42576. 완주하지 못한 선수

Level 1 완주하지 못한 선수

시간 복잡도: O(N logN), N = number of participants

1#include <bits/stdc++.h> 2using namespace std; 3 4string solution(vector<string> participant, vector<string> completion) { 5 map<string, int> p; 6 for(string s : participant) ++(p[s]); 7 for(string s : completion) ++(p[s]); 8 9 auto it = p.begin(); 10 while(it != p.end()) { 11 if(((it->second)&1)) return it->first; 12 ++it; 13 } 14}

처음 시작할 때 선수를 카운트하고, 도착했을 때 다시 카운팅한다. 최종적으로 카운팅한 값이 홀수인 경우, 해당 선수는 도착을 하지 못한 선수임을 의미한다.