class Solution {
public:
   int maxDepth(TreeNode* root) {
        if(!root) {
            return 0;
        }
        return 1 + max(maxDepth(root->left), maxDepth(root->right));
        // write code here
    }
    
    bool IsBalanced_Solution(TreeNode* pRoot) {
        if(!pRoot) {
            return true;
        }
        int leftDep = maxDepth(pRoot->left);
        int rightDep = maxDepth(pRoot->right);
        bool flag = abs(leftDep-rightDep) <= 1;
        return IsBalanced_Solution(pRoot->left) && IsBalanced_Solution(pRoot->right) && flag;
        

    }
};