updated at 2022. 12. 15. 오후 4:10:12
This commit is contained in:
@@ -1,25 +1,19 @@
|
||||
// [문제 링크]: https://school.programmers.co.kr/learn/courses/30/lessons/42576
|
||||
|
||||
import java.util.*;
|
||||
import java.util.HashMap;
|
||||
|
||||
class Solution {
|
||||
public String solution(String[] participant, String[] completion) {
|
||||
String answer = "";
|
||||
HashMap<String, Integer> hm = new HashMap<>();
|
||||
for (String player : participant) hm.put(player, hm.getOrDefault(player, 0) + 1);
|
||||
for (String player : completion) hm.put(player, hm.get(player) - 1);
|
||||
|
||||
Arrays.sort(participant);
|
||||
Arrays.sort(completion);
|
||||
|
||||
for(int i=0; i<participant.length; i++) {
|
||||
if(!participant[i].equals(completion[i])) {
|
||||
answer = participant[i];
|
||||
break;
|
||||
for (String key : hm.keySet()) {
|
||||
if (hm.get(key) != 0){
|
||||
answer = key;
|
||||
}
|
||||
if(i == completion.length) {
|
||||
answer = participant[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return answer;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user