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<>();
|
List<Integer> topK = new ArrayList<>();
|
||||||
for (int i = buckets.length - 1; i >= 0 && topK.size() < k; i--) {
|
for (int i = buckets.length - 1; i >= 0 && topK.size() < k; i--) {
|
||||||
if (buckets[i].size() <= (k - topK.size())) {
|
if (buckets[i] != null) {
|
||||||
topK.addAll(buckets[i]);
|
if (buckets[i].size() <= (k - topK.size())) {
|
||||||
} else {
|
topK.addAll(buckets[i]);
|
||||||
topK.addAll(buckets[i].subList(0, k - topK.size()));
|
} else {
|
||||||
|
topK.addAll(buckets[i].subList(0, k - topK.size()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return topK;
|
return topK;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user