1
class Solution {
2
public int[] topKFrequent(int[] nums, int k) {
3
Map<Integer, Integer> map = new HashMap<>();
4

5
for (int num : nums) {
6
map.merge(num, 1, Integer::sum);
7
}
8

9
return map.entrySet().stream()
10
.sorted(Map.Entry.comparingByValue(Comparator.reverseOrder()))
11
.map(Map.Entry::getKey)
12
.mapToInt(x -> x)
13
.limit(k)
14
.toArray();
15
}
16
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0