/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:
int height(TreeNode *node){
if(node==NULL){
return 0;
}
else{
return max(height(node->left),height(node->right))+1;
}
}
bool isBalanced(TreeNode* root) {
if(root==NULL)
{
return true;
}
int l=height(root->left);
int r=height(root->right);
if(abs(l-r)>1){
return false;
}
else{
return isBalanced(root->left)&&isBalanced(root->right);
}
}
};