class Solution { public: bool IsBalanced_Solution(TreeNode* pRoot) { if(pRoot==NULL) return true; int l = fun(pRoot->left); int r = fun(pRoot->right); if(abs(l-r)>1) return false; return IsBalanced_Solution(pRoot->left)&&IsBalanced_Solution(pRoot->right); } int fun(TreeNode* root) { if(root==NULL) return 0; else return max(fun(root->left)+1, fun(root->right)+1); } };