【剑指offer】平衡二叉树
题目:输入一棵二叉树,判断该二叉树是否是平衡二叉树。
class Solution { public: bool IsBalanced_Solution(TreeNode* pRoot) { if (pRoot == NULL) return true; return IsBalanced_Solution(pRoot->left) && IsBalanced_Solution(pRoot->right)&&(abs(getHeight(pRoot->left)-getHeight(pRoot->right))<=1); } int getHeight(TreeNode* root) { if (root == NULL) return 0; return max(getHeight(root->left), getHeight(root->right))+1; } };