Output Limit Exceeded. But correct Code


  • 0
    P

    Code below
    I get a Output Limit Exceeded error for the test case [6,1,null,null,3,2,5,null,null,4], even though the output the code gives (["6->1->3->2","6->1->3->5->4"]) perfectly matched the expected output (["6->1->3->2","6->1->3->5->4"])

    Please tell me how to fix!

    class Solution:
        # @param {TreeNode} root
        # @return {string[]}
        #BFS way
        ret=[]
        def binaryTreePaths(self, root):
            if root==None:
                return
            def bTPaths(root, s):
                if root==None:
                    return
                s+=str(root.val)
                if root.left==None and root.right==None:
                    self.ret.append(s)
                    return
                bTPaths(root.left, s)
                bTPaths(root.right, s)
            bTPaths(root, "")
            for i in range(len(self.ret)):
                self.ret[i]="->".join(self.ret[i])
            return self.ret
    
    

Log in to reply
 

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