46ms python solution , easy to undersyand


  • 0
    W
        if not head or not head.next:     
            return head
        list1=[]
        p=head
        while p:
            list1.append(p.val)
            p=p.next
        list1=list1[::-1]
        p=head
        i=0
        while p:
            p.val=list1[i]
            p=p.next
            i+=1
        return head

Log in to reply
 

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