- Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy path_1560.java
51 lines (48 loc) · 1.7 KB
/
_1560.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
42
43
44
45
46
47
48
49
50
51
packagecom.fishercoder.solutions.secondthousand;
importjava.util.ArrayList;
importjava.util.Collections;
importjava.util.HashMap;
importjava.util.List;
importjava.util.Map;
publicclass_1560 {
publicstaticclassSolution1 {
publicList<Integer> mostVisited(intn, int[] rounds) {
List<Integer> result = newArrayList<>();
Map<Integer, Integer> map = newHashMap<>();
for (inti = 0; i < rounds.length - 1; i++) {
if (rounds[i] > rounds[i + 1]) {
if (i == 0) {
map.put(rounds[i], 1);
}
for (intj = rounds[i] + 1; j <= n; j++) {
map.put(j, map.getOrDefault(j, 0) + 1);
}
for (intj = 1; j <= rounds[i + 1]; j++) {
map.put(j, map.getOrDefault(j, 0) + 1);
}
} else {
intj;
if (i == 0) {
j = rounds[i];
} else {
j = rounds[i] + 1;
}
for (; j <= rounds[i + 1]; j++) {
map.put(j, map.getOrDefault(j, 0) + 1);
}
}
}
intmostVisitedCount = 0;
for (intkey : map.keySet()) {
mostVisitedCount = Math.max(mostVisitedCount, map.get(key));
}
for (intkey : map.keySet()) {
if (map.get(key) == mostVisitedCount) {
result.add(key);
}
}
Collections.sort(result);
returnresult;
}
}
}