PYTHON 42ms 97th percentile solution O(n) time O(1) space

  • 0
    class Solution(object):
        def reverseList(self, head):
            :type head: ListNode
            :rtype: ListNode
            if not head:
                return None
            prev = head
            probe =
   = None # forgot this one initially
            while probe != None:
                nxt = 
       = prev
                prev = probe
                probe = nxt
            return prev

Log in to reply

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