Merge pull request #583 from xpluto/modify-leetcode-347

edit leetcode 347
This commit is contained in:
CyC2018 2019-02-26 11:25:09 +08:00 committed by GitHub
commit 9a794b889c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -404,7 +404,11 @@ 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] != null) {
topK.addAll(buckets[i]);
if (buckets[i].size() <= (k - topK.size())) {
topK.addAll(buckets[i]);
} else {
topK.addAll(buckets[i].subList(0, k - topK.size()));
}
}
}
return topK;