/** * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * }; */ /** * * @param pRoot TreeNode类 * @return bool布尔型 */ int Balanced(struct TreeNode* pRoot){ int left=1,right=1; if(pRoot){ left+=Balanced(pRoot->left); right+=Balanced(pRoot->right); return left>right?left:right; } return 0; } bool IsBalanced_Solution(struct TreeNode* pRoot ) { // write code here int left=0,right=0; if(pRoot==NULL) return true; else{ left=Balanced(pRoot->left); right=Balanced(pRoot->right); if(abs(left-right)>1)return false; } return true&&IsBalanced_Solution(pRoot->left)&&IsBalanced_Solution(pRoot->right); }