Simple python iterative solution

  • 1

    Simple python solution with 3 ListNodes.

    def reverseList(self, head):
            first = head
            current = None
            previous = None
            while first:
                current = first
                first =
       = previous
                previous = current
            return current

  • 0

    You can do it shorter in Python:

    def reverseList(self, head):
        prev = None
        while head:
  , prev, head = prev, head,
        return prev

Log in to reply

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