- Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy path_3005.java
28 lines (26 loc) · 810 Bytes
/
_3005.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
packagecom.fishercoder.solutions.fourththousand;
importjava.util.HashMap;
importjava.util.Map;
publicclass_3005 {
publicstaticclassSolution1 {
publicintmaxFrequencyElements(int[] nums) {
Map<Integer, Integer> map = newHashMap<>();
for (intnum : nums) {
map.put(num, map.getOrDefault(num, 0) + 1);
}
intmaxFreq = 0;
for (intkey : map.keySet()) {
if (map.get(key) > maxFreq) {
maxFreq = map.get(key);
}
}
intresult = 0;
for (intkey : map.keySet()) {
if (map.get(key) == maxFreq) {
result += map.get(key);
}
}
returnresult;
}
}
}