题解 | #判断是不是平衡二叉树#
判断是不是平衡二叉树
https://www.nowcoder.com/practice/8b3b95850edb4115918ecebdf1b4d222
class Solution { public: int heigh(TreeNode* pRoot){ if (!pRoot) return 0; int left = heigh(pRoot->left); int right = heigh(pRoot->right); if (abs(left - right) >= 2) return -1; if (left == - 1 || right == -1) return -1; return max(left, right) + 1; } bool IsBalanced_Solution(TreeNode* pRoot) { return heigh(pRoot) == -1 ? false : true; } };