标签:题目 二叉树 amp nod bool lan getheight turn root
题目:输入一棵二叉树,判断该二叉树是否是平衡二叉树。
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; } };
标签:题目 二叉树 amp nod bool lan getheight turn root
原文地址:https://www.cnblogs.com/lettleshel/p/10202029.html