Python O(1) space

  • 0
        def insertionSortList(self, head):
            if not head: return
            buffr = ListNode(None)
  , jP, j = head, head,
            while j:
                if j.val > jP.val: # already in place
                    jP, j = j,
                    i = buffr
                    while != j and < j.val: # look for insertion spot
                        i =
          ,,, j = j,,,

Log in to reply

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