class Solution(object):
def sortList(self, head):
"""
:type head: ListNode
:rtype: ListNode
"""
res=[]
while head:
res.append(head.val)
head=head.next
res.sort()
p=ListNode(0)
s=p
for r in res:
p.next=ListNode(r)
p=p.next
return s.next
python leetcode 148. Sort List
最新推荐文章于 2023-12-18 20:15:11 发布
本文深入探讨了链表排序算法的实现过程,通过将链表转换为数组进行排序,然后重新构建链表的方法,详细解释了如何高效地对链表进行排序。此方法适用于需要对链表数据进行快速排序的场景。

1404

被折叠的 条评论
为什么被折叠?



