-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem_01.java
More file actions
27 lines (22 loc) · 940 Bytes
/
Problem_01.java
File metadata and controls
27 lines (22 loc) · 940 Bytes
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
import java.util.HashMap;
public class Problem_01 {
// https://school.programmers.co.kr/learn/courses/30/lessons/42576
public static String solution(String[] participant, String[] completion) {
HashMap<String, Integer> map = new HashMap<>(); // key 중복 안됨(확인 필요)
for (String player : participant)
map.put(player, map.getOrDefault(player, 0) + 1);
for (String player : completion)
map.put(player, map.get(player) - 1);
for (String key : map.keySet()) { //순서 무관
if (map.get(key) != 0)
return key;
}
return "";
}
public static void main(String[] args) {
String[] participant = {"mislav", "stanko", "mislav", "ana"};
String[] completion = {"stanko", "ana", "mislav"};
String answer = solution(participant, completion);
System.out.println("answer: " + answer);
}
}