int NodeHeight(TreeNode* node){

if(!node) return 0;

return max(NodeHeight(node->left)+1,NodeHeight(node->right)+1);

}

bool isBalanced(TreeNode* root) {

if(!root) return true;

return abs(NodeHeight(root->left)-NodeHeight(root->right))<=1 && isBalanced(root->left) && isBalanced(root->right);

}