classSolution:defsortArray(self, nums: List[int])-> List[int]:
n=len(nums)defadjustHeap(n,i):
large=i
l,r=2*i+1,2*i+2if l<n and nums[l]>nums[large]:
large=l
if r<n and nums[r]>nums[large]:
large=r
if large!=i:
nums[large],nums[i]=nums[i],nums[large]
adjustHeap(n,large)for i inrange(n//2,-1,-1):
adjustHeap(n,i)for i inrange(n-1,-1,-1):
nums[i],nums[0]=nums[0],nums[i]
adjustHeap(i,0)#每次固定最后一个位置return nums