코딩테스트 연습
- 완주하지 못한 선수
해시 테이블을 사용해서 문제를 풀었다.
unordered_map을 사용했고, participant의 원소 개수에 비례하는 복잡도를 가진다.
#include <string>
#include <vector>
#include <unordered_map>
using namespace std;
string solution(vector<string> participant, vector<string> completion) {
string answer = "";
unordered_map <string, int> m;
for(auto& i : participant) m[i]++;
for(auto& i : completion) m[i]--;
for(auto& i : m){
if(i.second > 0){
answer = i.first;
break;
}
}
return answer;
}