- Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy path_1862.java
32 lines (30 loc) · 1019 Bytes
/
_1862.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
packagecom.fishercoder.solutions.secondthousand;
importjava.util.ArrayList;
importjava.util.List;
importjava.util.TreeMap;
publicclass_1862 {
publicstaticclassSolution1 {
/*
* TODO: this results in TLE, fix it.
*/
publicintsumOfFlooredPairs(int[] nums) {
TreeMap<Integer, Integer> map = newTreeMap<>();
for (intnum : nums) {
map.put(num, map.getOrDefault(num, 0) + 1);
}
List<Integer> list = newArrayList<>(map.keySet());
intmod = 1000000007;
longsum = 0L;
for (inti = list.size() - 1; i >= 0; i--) {
for (intj = i; j >= 0; j--) {
sum +=
(list.get(i) / list.get(j))
* map.get(list.get(j))
* map.get(list.get(i));
sum %= mod;
}
}
return (int) sum;
}
}
}