mirror of
https://github.com/krahets/hello-algo.git
synced 2026-07-07 13:14:19 +00:00
build
This commit is contained in:
@@ -306,7 +306,7 @@ comments: true
|
||||
siftDown(nums: &nums, n: nums.count, i: i)
|
||||
}
|
||||
// 从堆中提取最大元素,循环 n-1 轮
|
||||
for i in stride(from: nums.count - 1, to: 0, by: -1) {
|
||||
for i in nums.indices.dropFirst().reversed() {
|
||||
// 交换根节点与最右叶节点(交换首元素与尾元素)
|
||||
nums.swapAt(0, i)
|
||||
// 以根节点为起点,从顶至底进行堆化
|
||||
|
||||
Reference in New Issue
Block a user