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