class Solution(object):
def insertionSortList(self, head):
cur = dummy = ListNode(-1)
while head:
while cur.next and cur.next.val<head.val: #找到插入点
cur = cur.next
#插入新的结点
cur_next = cur.next
head_next = head.next
cur.next = head
cur.next.next = cur_next
head = head_next
cur = dummy #将指针返回到结果的头部
return dummy.next
Python 插入法实现链表排序
最新推荐文章于 2023-11-16 16:02:44 发布