forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_3005.java
28 lines (26 loc) · 795 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
package com.fishercoder.solutions;
import java.util.HashMap;
import java.util.Map;
public class _3005 {
public static class Solution1 {
public int maxFrequencyElements(int[] nums) {
Map<Integer, Integer> map = new HashMap<>();
for (int num : nums) {
map.put(num, map.getOrDefault(num, 0) + 1);
}
int maxFreq = 0;
for (int key : map.keySet()) {
if (map.get(key) > maxFreq) {
maxFreq = map.get(key);
}
}
int result = 0;
for (int key : map.keySet()) {
if (map.get(key) == maxFreq) {
result += map.get(key);
}
}
return result;
}
}
}