Update Leetcode 题解.md

This commit is contained in:
CyC2018 2019-02-26 15:14:52 +08:00
commit cc9dd446f2

View File

@ -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;