static int flag=0;
public boolean isBalanced(TreeNode root) {
flag=0;
travel12(root);
if(flag==1){
return false;
} else {
return true;
}
}
public int travel12(TreeNode node){
if(node==null){
return 0;
}
int hl=travel12(node.left)+1;
int hr=travel12(node.right)+1;
if(hl-hr>1||hr-hl>1){
flag=1;
}
return hl>hr?hl:hr;
}
标签:node,return,hr,是不是,int,flag,二叉树,hl,平衡
From: https://www.cnblogs.com/sjj123/p/16620641.html