Python, Why my Solution be Time Limit Exceeded


  • 0
    X
    def countNodes(self, root):
        if root == None:
            return 0
            
        return 1 + self.helper(root)
        
    def helper(self, n):
        if n.right != None:
            return 2 + self.helper(n.left) + self.helper(n.right)
        else:
            if n.left != None:
                return 1
            else:
                return 0

Log in to reply
 

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