/**
 * struct TreeNode {
 *	int val;
 *	struct TreeNode *left;
 *	struct TreeNode *right;
 * };
 */

class Solution {
public:
    /**
     * 
     * @param root TreeNode类 
     * @return bool布尔型
     */
    int getTreeHight(TreeNode* root)
    {
        if(!root)
        {
            return 0;
        }
        if (!root->left&&!root->right)
        {
            return 1;
        }
        return max(getTreeHight(root->left),getTreeHight(root->right))+1;

    }
    bool isBalanced(TreeNode* root) {
        // write code here
        int hight = 0;
        if(root == nullptr)
        {
            return true;
        }
        if (!root->left&&!root->right)
        {
            return true;
        }
        return (abs(getTreeHight(root->left)-getTreeHight(root->right))>1?
                false:true&&isBalanced(root->left)&&isBalanced(root->right));

    }
};