mirror of
https://github.com/lWolvesl/leetcode.git
synced 2026-01-13 02:38:37 +08:00
250923
This commit is contained in:
20
25/09/3005.java
Normal file
20
25/09/3005.java
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user