class Solution{
public:
int dep(TreeNode* t)
{
if(t==NULL)
{
return 0;
}
else{
int l=dep(t->left);
int r=dep(t->right);
if(l>r) return l+1;
else return r+1;;
}
}
bool isBalanced(TreeNode* root) {
int i,j;
if(root==NULL)
{
return true;
}
i=dep(root->left);
j=dep(root->right);
if(abs(i-j)<=1)
{
return true;
}
else
{
return dep(root->left) - dep(root->right) <= 1 && isBalanced(root->left) && isBalanced(root->right);; //把return false换成这一串就可以通过
}
}
};
[1,2,2,3,null,null,3,4,null,null,4]
这是一颗树吗?