classTree { public: intdeep(TreeNode* root) { //深度计算 if (root == nullptr) return0; int l = 0, r = 0; l = deep(root->lchild); r = deep(root->rchild); return l > r ? l + 1 : r + 1; } boolIsBalanced_Solution(TreeNode* pRoot) { //是否为平衡二叉树 if (pRoot == nullptr) returntrue; int left = deep(pRoot->lchild); int right = deep(pRoot->rchild); if (abs(left - right) <= 1) returntrue; else returnfalse; } };