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
|
// [문제 링크]: https://school.programmers.co.kr/learn/courses/30/lessons/42576
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.HashMap;
|
||||||
|
|
||||||
class Solution {
|
class Solution {
|
||||||
public String solution(String[] participant, String[] completion) {
|
public String solution(String[] participant, String[] completion) {
|
||||||
String answer = "";
|
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);
|
for (String key : hm.keySet()) {
|
||||||
Arrays.sort(completion);
|
if (hm.get(key) != 0){
|
||||||
|
answer = key;
|
||||||
for(int i=0; i<participant.length; i++) {
|
|
||||||
if(!participant[i].equals(completion[i])) {
|
|
||||||
answer = participant[i];
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
if(i == completion.length) {
|
|
||||||
answer = participant[i];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return answer;
|
return answer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user