二叉平衡树
题目描述:
代码如下:
class Solution { public: int get_depth(TreeNode *pRoot) { if(!pRoot) return 0; return max(get_depth(pRoot->left) + 1 , get_depth(pRoot->right) + 1); } bool IsBalanced_Solution(TreeNode* pRoot) { if(pRoot == NULL) return true; bool flag = true; int left_depth = get_depth(pRoot->left); int right_depth = get_depth(pRoot->right); if(abs(left_depth - right_depth) <= 1) flag = flag && true; else flag = flag && false; return(flag && IsBalanced_Solution(pRoot->left) && IsBalanced_Solution(pRoot->right)); } };