Medium · Arrays
Heap sort
Given an integer array nums, sort it in place into non-decreasing order with heap sort (build a max-heap, then repeatedly move its root to the end of the shrinking heap); the function returns nothing.
Examples
Example 1
[5, 2, 8, 1, 9, 3]Output: [1, 2, 3, 5, 8, 9]
Example 2
[8, 7, 6, 5, 4, 3, 2] · reversedOutput: [2, 3, 4, 5, 6, 7, 8]
Rebuild it in the studio
Read every interview problem free. Ten rooms need no account. A token opens a problem in full — Pro never counts.