临海做网站公司,wordpress赚钱方法,石家庄网站建设找哪家,网站开发公司推荐心路历程#xff1a;
这道题通过很简单#xff0c;但是如果想要用O(1)的空间复杂度O(nlogn)的时间复杂度的话#xff0c;可能得需要双指针快排的思路。
解法#xff1a;遍历模拟
# Definition for singly-linked list.
# class ListNode:
# def __init__(self, val0…
心路历程
这道题通过很简单但是如果想要用O(1)的空间复杂度O(nlogn)的时间复杂度的话可能得需要双指针快排的思路。
解法遍历模拟
# Definition for singly-linked list.
# class ListNode:
# def __init__(self, val0, nextNone):
# self.val val
# self.next next
class Solution:def sortList(self, head: Optional[ListNode]) - Optional[ListNode]:res []t1 headwhile t1:res.append(t1.val)t1 t1.nextres.sort()t2 headc 0while t2:t2.val res[c]c1t2 t2.nextreturn head