class Solution {
public:
int getdepth(TreeNode* root){
if(root == nullptr) return 0;
return 1+max(getdepth(root->left),getdepth(root->right));
}
public:
bool isBalanced(TreeNode* root) {
if(root == nullptr) return true;
bool left = isBalanced(root->left);
bool right = isBalanced(root->left);
if(abs(getdepth(root->left)-getdepth(root->right))>1)
return false;
else
return left&&right;
}
};
好兄弟,第11行那里是 bool right = isBalanced(root->right);
这个是检查右子树的