mirror of
https://github.com/krahets/hello-algo.git
synced 2026-08-19 06:50:59 +00:00
feat(go): add iterration/recursion & fix bugs (#698)
This commit is contained in:
@@ -26,7 +26,7 @@ func newHeap() *maxHeap {
|
||||
func newMaxHeap(nums []any) *maxHeap {
|
||||
// 将列表元素原封不动添加进堆
|
||||
h := &maxHeap{data: nums}
|
||||
for i := len(h.data) - 1; i >= 0; i-- {
|
||||
for i := h.parent(len(h.data) - 1); i >= 0; i-- {
|
||||
// 堆化除叶节点以外的其他所有节点
|
||||
h.siftDown(i)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user