Leetcode#110. 平衡二叉树,C++实现
1. 题目
2. 方法一
2.1. 代码
class Solution {
bool result=true;
public:
bool isBalanced(TreeNode* root) {
Max_depth(root);
return result;
}
int Max_depth(TreeNode* head)
{
if(head==NULL) return 0;
int left=Max_depth(head->left);
int right=Max_depth(head->right);
if(abs(left-right)>1)
result=false;
return max(left,right)+1;
}
};