本文共 780 字,大约阅读时间需要 2 分钟。
class Solution(object): def insertionSortList(self, head): """ :type head: ListNode :rtype: ListNode """ if not head or not head.next: return head p=head mystack=[p] p=p.next while p: q=p.next p.next=None if mystack[-1].val<=p.val: mystack[-1].next=p mystack.append(p) else: for i in range(len(mystack)): if p.val <= mystack[i].val: p.next=mystack[i] if i>0: mystack[i-1].next=p mystack.insert(i,p) break p=q mystack[-1].next=None return mystack[0]
转载地址:http://lgxhj.baihongyu.com/