auto commit
This commit is contained in:
parent
cc9dd446f2
commit
d526ebd5fd
|
@ -403,12 +403,10 @@ 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) {
|
||||
if (buckets[i].size() <= (k - topK.size())) {
|
||||
topK.addAll(buckets[i]);
|
||||
} else {
|
||||
topK.addAll(buckets[i].subList(0, k - topK.size()));
|
||||
}
|
||||
if (buckets[i].size() <= (k - topK.size())) {
|
||||
topK.addAll(buckets[i]);
|
||||
} else {
|
||||
topK.addAll(buckets[i].subList(0, k - topK.size()));
|
||||
}
|
||||
}
|
||||
return topK;
|
||||
|
|
BIN
docs/notes/pics/cb5d2258-a60e-4364-94a7-3429a3064554_200.png
Normal file
BIN
docs/notes/pics/cb5d2258-a60e-4364-94a7-3429a3064554_200.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 37 KiB |
|
@ -382,7 +382,7 @@ public class Insertion<T extends Comparable<T>> extends Sort<T> {
|
|||
|
||||
希尔排序使用插入排序对间隔 h 的序列进行排序。通过不断减小 h,最后令 h=1,就可以使得整个数组是有序的。
|
||||
|
||||
<div align="center"> <img src="pics/1_200.png"/> </div><br>
|
||||
<div align="center"> <img src="pics/cb5d2258-a60e-4364-94a7-3429a3064554_200.png"/> </div><br>
|
||||
|
||||
```java
|
||||
public class Shell<T extends Comparable<T>> extends Sort<T> {
|
||||
|
|
BIN
docs/pics/cb5d2258-a60e-4364-94a7-3429a3064554_200.png
Normal file
BIN
docs/pics/cb5d2258-a60e-4364-94a7-3429a3064554_200.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 37 KiB |
Loading…
Reference in New Issue
Block a user