```
bool isBalanced(TreeNode* root) {
if(root == NULL)
return true;
int leftdeep = deepofBinary(root->left);
int rightdeep = deepofBinary(root->right);
if(leftdeep-rightdeep > 1 || rightdeep-leftdeep > 1)
return false;
else
return isBalanced(root->left) && isBalanced(root->right);
}
int deepofBinary(TreeNode* root)
{
if(root == NULL)
return 0;
int left = 1 + deepofBinary(root->left);
int right = 1 + deepofBinary(root->right);
return left>right?left:right;
}
```