/**
* 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 TreeHeight(TreeNode* root){
if (!root) return 0;
return max(TreeHeight(root->left), TreeHeight(root->right))+1;
}
bool isBalanced(TreeNode* root) {
bool res = true;
if (root){
if (abs(TreeHeight(root->left) - TreeHeight(root->right)) > 1) return false;
else res = isBalanced(root->left) && isBalanced(root->right);
}
return res;
}
};