Simple iterative python solution


  • 1
    A
    def reverseList(self, head):
        if not head or not head.next:
            return head
        ret = None
        while head:
            tmp = head
            head = head.next
            tmp.next = ret
            ret = tmp
        return ret

Log in to reply
 

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