Why does my python recursive solution always return None? Thanks

  • 0
    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

    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.