/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
int Depth(struct TreeNode* root)
{
if (root == NULL)
return 0;
int leftDepth = Depth(root->left);
int rightDepth = Depth(root->right);
if (leftDepth > rightDepth)
return leftDepth + 1;
return rightDepth + 1;
}
//左右子树高度差不超过1 且左右子树都是平衡二叉树 当前树才是平衡二叉树
bool isBalanced(struct TreeNode* root){
if (root == NULL)
return true;
if (abs(Depth(root->left) - Depth(root->right)) > 1)
return false;
return isBalanced(root->left) && isBalanced(root->right);
}