Python AC solution


  • 0
    class Solution(object):
        def insertionSortList(self, head):
            fakeHead = ListNode(-sys.maxint)
            fakeHead.next = head
            t = fakeHead
            while t.next != None:
                h = fakeHead
                if t.val <= t.next.val:
                    t = t.next
                    continue
                while h.next != t.next and h.next.val < t.next.val:
                    h = h.next
                addNode = t.next
                t.next = addNode.next
                addNode.next = h.next
                h.next = addNode
            return fakeHead.next
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.