Share my python solution,AC


  • 0
    class Solution(object):
    def reverselist(self,head):
        prev=None
        if not head:return head
        curr=head
        while curr:
            next=curr.next
            curr.next=prev
            prev=curr
            curr=next
        return prev
    def reorderList(self, head):
        """
        :type head: ListNode
        :rtype: void Do not return anything, modify head in-place instead.
        """
        if not head:return
        p,length=head,0
        while p:
            p=p.next
            length+=1
        ncount=length/2
        p=head
        while ncount>0:
            p=p.next
            ncount-=1
        if p:q=p.next####
        p.next=None
        q=self.reverselist(q)  #reverse left half
        p=head
        while p and q: #insert left into right helf
            k=p.next
            r=q.next
            p.next=q
            q.next=k
            p=k
            q=r
        #return head

Log in to reply
 

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