平衡二叉树
作者:
稀饭粥95 | 来源:发表于
2018-08-29 21:01 被阅读12次
public class Solution {
public boolean isBalanced(TreeNode root ,int[] depth ){
if(root==null){
depth[0]=0;
return true;
}
int []da = new int[1];
int []db = new int[1];
if(isBalanced(root.left,da)&&
isBalanced(root.right,db)){
if(Math.abs(da[0]-db[0])<=1){
int max = da[0]>db[0]?da[0]:db[0];
depth[0] = 1 + max;
return true;
}
}
return false;
}
public boolean IsBalanced_Solution(TreeNode root) {
return isBalanced(root,new int[1]);
}
}
本文标题:平衡二叉树
本文链接:https://www.haomeiwen.com/subject/gaxlwftx.html
网友评论