Why does my python recursive solution always return None? Thanks


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

    nvm. I forgot to call return. lols


  • 0
    K

    you need to return in reverseList()
    Like this: return self.recurse(head, None)


Log in to reply
 

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