Update Leetcode 题解.md
This commit is contained in:
commit
cc9dd446f2
|
@ -403,10 +403,12 @@ public List<Integer> topKFrequent(int[] nums, int k) {
|
|||
}
|
||||
List<Integer> topK = new ArrayList<>();
|
||||
for (int i = buckets.length - 1; i >= 0 && topK.size() < k; i--) {
|
||||
if (buckets[i].size() <= (k - topK.size())) {
|
||||
topK.addAll(buckets[i]);
|
||||
} else {
|
||||
topK.addAll(buckets[i].subList(0, k - topK.size()));
|
||||
if (buckets[i] != null) {
|
||||
if (buckets[i].size() <= (k - topK.size())) {
|
||||
topK.addAll(buckets[i]);
|
||||
} else {
|
||||
topK.addAll(buckets[i].subList(0, k - topK.size()));
|
||||
}
|
||||
}
|
||||
}
|
||||
return topK;
|
||||
|
|
Loading…
Reference in New Issue
Block a user