待续!!!!!(这种方法效率不高,还有更高的效率方法)
class Solution {
public:
//二叉树的定义:是一棵空数,或它的左右两个子树的高度差的绝对值不超过1,
//并且左右子树也都是一棵平衡二叉树。
int TreeDepth(TreeNode* pRoot)
{
if(pRoot==NULL)
return 0;
int m=TreeDepth(pRoot->left);
int n=TreeDepth(pRoot->right);
return 1+(m>n?m:n);
}
bool IsBalanced_Solution(TreeNode* pRoot) {
if(pRoot==NULL)
return true;
int m=TreeDepth(pRoot->left);
int n=TreeDepth(pRoot->right);
if(abs(m-n)>1)
return false;
return IsBalanced_Solution(pRoot->left) && IsBalanced_Solution(pRoot->right);
}
};