Python, Why my Solution be Time Limit Exceeded

  • 0
    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)
            if n.left != None:
                return 1
                return 0

Log in to reply

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