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 判断是否为平衡二叉树的全部内容,更多相关jz79内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复