作者:
Rushia (みけねこ的鼻屎)
2023-03-02 00:20:45912. Sort an Array
給你一個陣列請排序他,時間複雜度最多O(nlogn),空間複雜度盡可能少。
Example:
Input: nums = [5,2,3,1]
Output: [1,2,3,5]
Explanation: After sorting the array, the positions of some numbers are not
changed (for example, 2 and 3), while the positions of other numbers are
changed (for example, 1 and 5).
思路:
1.因為題目需求時間複雜度O(nlogn),所以只能用高等排序來求解,其中HeapSort和
QuickSort空間用的最少所以挑這兩個其一來實現即可。
Java Code: