/*
struct TreeNode {
int val;
struct TreeNode *left;
struct TreeNode *right;
TreeNode(int x) :
val(x), left(NULL), right(NULL) {
}
};*/
class Balance {
public:
bool isBalance(TreeNode* root) {
if(root==NULL)
return true;
while(
isBalance(root->left)==true&&
isBalance(root->right)==true&&
du(root->right)-du(root->left)<=1&&
du(root->left)-du(root->right)<=1)
return true;
return false;}
int du(TreeNode* root){
if(root==NULL)
return 0;
return max(du(root->right),du(root->left))+1; }
};