Re: [閒聊] 每日LeetCode

作者: Rushia (みけねこ的鼻屎)   2023-03-02 00:20:45
912. 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:
作者: Che31128 (justjoke)   2023-03-02 00:26:00
大師
作者: moonoftree (月之樹)   2023-03-02 00:28:00
list.sort()
作者: a9486l (a9486l)   2023-03-02 00:39:00
大師
作者: idiont (supertroller)   2023-03-02 00:46:00
以前寫過很多次sort了 我決定用內建的蒙混過去

Links booklink

Contact Us: admin [ a t ] ucptt.com