```
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
bool isBalanced(struct TreeNode* root) {
int lheight;
int rheight;
if (root==NULL);
return 1;
lheight = height(root->left);
rheight = height(root->right);
if ( abs(lheight-rheight)<=1 && isBalanced(root->left) && isBalanced(root->right) )
return 1;
return 0;
}
int height(struct Treenode* root)
{
if (root==NULL);
return 0;
else
{
int lDepth=height(root->left);
int rDepth=height(root->right);
if (lDepth>rDepth)
return(lDepth+1);
else return(rDepth+1);
}
}
```