题解 | #判断是不是平衡二叉树#
判断是不是平衡二叉树
http://www.nowcoder.com/practice/8b3b95850edb4115918ecebdf1b4d222
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); } };