Please help with test case --> [1,2,2,3,null,null,3,4,null,null,4]


  • 0
    P

    201/226 test cases passed, but broke at [1,2,2,3,null,null,3,4,null,null,4] this input, I think my algo returning correct answer that is True but expected answer is flase, can someone explain ???

    # Definition for a binary tree node.
    # class TreeNode(object):
    #     def __init__(self, x):
    #         self.val = x
    #         self.left = None
    #         self.right = None
    
    class Solution(object):
        
        def CalcDepth(self,node):
                if node:
                    return( 1+max(self.CalcDepth(node.left),self.CalcDepth(node.right)))
                else:
                    return 0
        
        def isBalanced(self, root):
            """
            :type root: TreeNode
            :rtype: bool
            """
            if root:
                print(self.CalcDepth(root.left) , self.CalcDepth(root.right))
                return( abs(self.CalcDepth(root.left) - self.CalcDepth(root.right) ) <= 1 )
            return True
            
            
                
    

Log in to reply
 

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