# [1,2,2,3,3,3,3,4,4,4,4,4,4,null,null,5,5] should not the answer for this tree be false?

• /**

• Definition for a binary tree node.

• struct TreeNode {

• ``````int val;
``````
• ``````TreeNode *left;
``````
• ``````TreeNode *right;
``````
• ``````TreeNode(int x) : val(x), left(NULL), right(NULL) {}
``````
• };
*/
class Solution {
public:

int maxDepth(TreeNode* root)
{
if(root==NULL)
return 0;
return 1+max(maxDepth(root->left),maxDepth(root->right));
}

int minDepth(TreeNode* root)
{
if(root==NULL)
return 0;
return 1+min(minDepth(root->left),minDepth(root->right));
}

bool isBalanced(TreeNode* root) {
return (maxDepth(root)-minDepth(root)<=1);
}
};

the depth of the right sub tree of the root is 3, and the depth of the left sub tree of the root is 4.

the definition of "balanced" here is for "the depths of the two sub trees", not "the depths of all the leaves".

• thank you for answering my doubt!:)

• you are right ,at first i wrote the same code like him,thank you.

• You are right. I previously was checking is_balance_tree in my mind.
Thanks.

• This problem is misleading. There is no such a thing as "depth of a tree" (or subtree). It should be changed to "the height of each subtree".

• This post is deleted!

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