class Solution {
public:
bool res=true;
int dfs(TreeNode* root)//返回以root为根节点的子树深度
{
if(root==NULL) return 0;
int l=dfs(root->left),r=dfs(root->right);
if(abs(l-r)>1)
res=false;
return max(l,r)+1;
}
bool isBalanced(TreeNode* root) {
dfs(root);
return res;
}
};
标签:return,int,res,dfs,二叉树,平衡,root
From: https://www.cnblogs.com/tangxibomb/p/17379585.html