문제 링크
요약
- Corner case 를 잘 생각하자
최종
결과
- 같은이름의 인간이 들어올 수 있다는 점만 조심하면, 별 문제는 없다.
#include <string>
#include <vector>
#include <map>
using namespace std;
string solution(vector<string> participant, vector<string> completion) {
map<string, int> table;
for (auto &p : participant) {
if (table.find(p) != table.end()) {
table[p]++;
} else {
table.emplace(p, 1);
}
}
for (auto &c : completion) {
table[c]--;
}
for (auto &t : table) {
if (t.second) {
return t.first;
}
}
// Should not happen
return "";
}