Python easy solution


  • 0
    W

    O(n) space solution, easy to write but space can be reduced to O(1).

    def reorderList(self, head):
        if not head or not head.next: return 
        L = []
        while head:
            L.append(head)
            head = head.next
        for i in range(len(L)//2):
            L[i].next = L[len(L)-i-1]
            L[len(L)-i-1].next = L[i+1] 
        L[i+1].next = None

Log in to reply
 

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