-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest20.java
More file actions
41 lines (35 loc) · 1.18 KB
/
Copy pathTest20.java
File metadata and controls
41 lines (35 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package programmers;
import java.util.HashMap;
public class Test20 {
public String solution(String[] participant, String[] completion) {
String answer = "";
HashMap<String, Integer> map = new HashMap<>();
for (String player : participant) {
map.put(player, map.getOrDefault(player, 0) + 1);
}
for (String player : completion) {
map.put(player, map.getOrDefault(player, 0) - 1);
}
for (String key : map.keySet()) {
if (map.get(key) != 0) {
answer = key;
}
}
return answer;
}
public static void main(String[] args) {
String[] par = {"marina", "josipa", "nikola", "vinko", "filipa"};
String[] com = {"josipa", "filipa", "marina", "nikola"};
Test20 test = new Test20();
System.out.println(test.solution(par,com));
}
}
// Arrays.sort(participatn);
// Arrays.sort(completion);
// int i = 0;
// for (i = 0; i < completion.length; i++) {
// if (!participant[i].equals(completion[i])) {
// break;
// }
// }
// System.out.println(par[i]);