class Solution {

public:

bool isBalanced(TreeNode* root) {

deep(root,0);

if(flag)return false;

return true;

}

int flag=0;

int deep(TreeNode* root,int deepth){

if(root==NULL)return deepth;

int left=deepth,right=deepth;

left=deep(root->left,deepth+1);

right=deep(root->right,deepth+1);

if(abs(left-right)>1)flag=1;

return max(left,right);

}

};