public class Solution {
public boolean IsBalanced_Solution(TreeNode root) {
int dept = dept(root);
if(dept>=0) return true;
return false;
}
public int dept(TreeNode root){
if(root==null) return 0;
int left = dept(root.left);
if(left==-1) return -1;
int right = dept(root.right);
if(right==-1) return -1;
if(Math.abs(left-right)>1){
return -1;
}else{
return 1+Math.max(left,right);
}
}
}
jz79 判断是否为平衡二叉树
最新推荐文章于 2024-08-16 23:08:28 发布