Python concise solution, just 3 loops

  • 0
    #split linked list into two
    #reverse the second one
    #link them one by one
    class Solution(object):
        def reorderList(self, head):
            if not head:
                return None
            s = f = head1 = head 
                    s, f =,
                    f =
            pre,, head2 =, None, None     
            while pre:
      , pre, head2 = head2,, pre
            while head2:
      , head1 = head2,
      , head2 = head1,

Log in to reply

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