Beats 85% of python submissions.

  • 0
    # Def
    # class ListNode(object):
    #     def __init__(self, x):
    #         self.val = x
    # = None
    class Solution(object):
        def reverseList(self, head):
            :type head: ListNode
            :rtype: ListNode
            if head == None or == None:
                return head
                cur = head
                    nex =
                    #give current head pointer & next pointer
           = cur
                    cur = nex
                    #update the current head
                return cur

    I reverse the list one by one,kind of silly :P

Log in to reply

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