Python Recursion Implemention


  • 0
    F

    Python Recursion Implemention

    # Definition for singly-linked list.
    # class ListNode:
    #     def __init__(self, x):
    #         self.val = x
    #         self.next = None
    
    class Solution:
        def reverseList(self, head):
            """
            :type head: ListNode
            :rtype: ListNode
            """
            if not head or not head.next:
                return head
            second = head.next
            reverse = self.reverseList(second)
            second.next = head
            head.next = None
            
            return reverse
    
    
    

Log in to reply
 

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