- Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy path_1604.java
41 lines (39 loc) · 1.49 KB
/
_1604.java
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
packagecom.fishercoder.solutions.secondthousand;
importjava.util.ArrayList;
importjava.util.Collections;
importjava.util.HashMap;
importjava.util.List;
importjava.util.Map;
publicclass_1604 {
publicstaticclassSolution1 {
publicList<String> alertNames(String[] keyName, String[] keyTime) {
Map<String, List<String>> map = newHashMap<>();
for (inti = 0; i < keyName.length; i++) {
if (!map.containsKey(keyName[i])) {
map.put(keyName[i], newArrayList<>());
}
map.get(keyName[i]).add(keyTime[i]);
}
List<String> people = newArrayList<>();
for (Stringperson : map.keySet()) {
List<String> times = map.get(person);
List<Integer> minutes = newArrayList<>();
for (Stringtime : times) {
String[] hourAndMin = time.split(":");
Integerminute =
Integer.parseInt(hourAndMin[0]) * 60 + Integer.parseInt(hourAndMin[1]);
minutes.add(minute);
}
Collections.sort(minutes);
for (inti = 0; i < minutes.size() - 2; i++) {
if (minutes.get(i + 2) - minutes.get(i) <= 60) {
people.add(person);
break;
}
}
}
Collections.sort(people);
returnpeople;
}
}
}