/*
struct TreeNode {
int val;
struct TreeNode *left;
struct TreeNode *right;
TreeNode(int x) :
val(x), left(NULL), right(NULL) {
}
};*/
#include <algorithm>
#include <complex>
class Balance {
int check (TreeNode* root){
if(!root) return 0;
int lh = check(root->left);
if(lh == -1) return -1;
int rh = check(root->right);
if(rh == -1) return -1;
if(abs(lh - rh) > 1) return -1;
return max(lh, rh) +1;
}
public:
bool isBalance(TreeNode* root) {
// write code here
return check(root) != -1;
}
};

京公网安备 11010502036488号