题目描述:在O(n log n)时间复杂度和常数级空间复杂度下,对链表进行排序。
def sortList(self,head:ListNode):
result=[]
if head==None :
return None
while(head):
result.append(head.val)
head=head.next
result.sort()
temp=ListNode(result[0])
res=temp
for i in range(0,len(result)-1):
temp.next=ListNode(result[i+1])
temp=temp.next
return res