| 13 | class Solution { |
| 14 | public: |
| 15 | int check(TreeNode* root){ |
| 16 | if(root==NULL)return 0; |
| 17 | int lh=check(root->left); |
| 18 | int rh=check(root->right); |
| 19 | if(lh==-1 || rh==-1)return -1; |
| 20 | if(abs(lh-rh)>1)return -1; |
| 21 | return max(lh,rh)+1; |
| 22 | } |
| 23 | |
| 24 | bool isBalanced(TreeNode* root) { |
| 25 | return check(root)!=-1; |