This commit is contained in:
2025-09-23 01:56:29 +08:00
parent 3f58f483ff
commit f94834d397
3 changed files with 83 additions and 0 deletions

20
25/09/3005.java Normal file
View File

@@ -0,0 +1,20 @@
import java.util.HashMap;
import java.util.Map;
class Solution {
public int maxFrequencyElements(int[] nums) {
Map<Integer, Integer> map = new HashMap<>();
int max = 0, ans = 0;
for (int num : nums) {
map.put(num, map.getOrDefault(num, 0) + 1);
int c = map.get(num);
if (c > max) {
max = c;
ans = c;
} else if (c == max) {
ans += c;
}
}
return ans;
}
}