Playground/자바문제집
[프로그래머스] 완주하지 못한 선수
미숫가루설탕많이
2023. 5. 13. 16:36
import java.util.*;
class Solution {
public String solution(String[] participant, String[] completion) {
String answer = "";
HashMap<String, Integer> hm = new HashMap<>();
for (String str : completion) {
if (hm.containsKey(str)) {
hm.put(str, hm.get(str) + 1);
} else {
hm.put(str, 1);
}
}
for (String str : participant) {
if (hm.containsKey(str)) {
if (hm.get(str) > 0) {
hm.put(str, hm.get(str) - 1);
} else {
answer = str;
break;
}
}
else {
answer = str;
break;
}
}
return answer;
}
}