Python 3-line solution, beats 90%


  • 0
    T
    class Solution(object):
        def reverseList(self, head):
            """
            :type head: ListNode
            :rtype: ListNode
            """
            prev, curr = None, head
            while curr: curr.next, prev, curr = prev, curr, curr.next
            return prev
    

Log in to reply
 

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