难度:中等
题目描述:
思路总结:为什么链表题中等难度的都能做出来,而其它类型的题不行呢,值得思考。
题解一:
class Solution:
def insertionSortList(self, head: ListNode) -> ListNode:
dummy = ListNode(0)
while head:
cur = dummy
nxt = head.next
while cur:
if not cur.next:
cur.next = head
head.next = None
elif head.val < cur.next.val:
tmp = cur.next
cur.next = head
head.next = tmp
break
cur = cur.next
head = nxt
return dummy.next