import java.util.HashMap;
import java.util.Map;
public class Solution {
public String solution(String[] participant, String[] completion) {
Map<String, Integer> count = new HashMap<>();
for (String name : participant) {
count.putIfAbsent(name, 0);
count.put(name, count.get(name) + 1);
}
for (String name : completion) {
int v = count.get(name) - 1;
count.put(name, v);
if (v == 0) count.remove(name);
}
return count.keySet().iterator().next();
}
}
keySet()를 호출하면 Map에 담긴 key들을 Set형태로 반환,
이를 순회하기 위해 iterator() 메서드를 호출하고,
첫 번째 원소를 가져오기 위해 next()를 호출하면 된다.