提交 c4f81ae6 编写于 作者: GreyZeng's avatar GreyZeng

update heap sort

上级 b21c9af6
......@@ -16,10 +16,13 @@ public class Code_DistanceLessK {
heap.offer(arr[i]);
}
int index = 0;
for (; i < arr.length || !heap.isEmpty(); i++) {
if (i < arr.length) {
heap.offer(arr[i]);
}
// O(N*logK)
for (; i < arr.length; i++) {
heap.offer(arr[i]);
// 移动一定不会超过K次
arr[index++] = heap.poll();
}
while (!heap.isEmpty()) {
arr[index++] = heap.poll();
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册