class Solution {
public:
bool isBalanced(TreeNode* root)
{
return p(root)!=-1;
}
int p(TreeNode* root){
if(root==NULL)return 0;
int l=p(root->left);
if(l==-1)return -1;
int r=p(root->right);
if(r==-1)return -1;
return abs(l-r)>1?-1:1+max(l,r);
}
};
110. 平衡二叉树
最新推荐文章于 2022-12-02 17:20:00 发布