您的位置:首页 > 其它

Balanced Binary Tree

2014-02-06 15:20 78 查看
public class Solution {
public boolean isBalanced(TreeNode root) {
if(root==null) return true;
if(checkHeight(root)==-1) return false;
return true;
}
public int checkHeight(TreeNode root){
if(root==null) return 0;
int left = checkHeight(root.left);
int right = checkHeight(root.right);
if(right==-1||left==-1) return -1;
if(Math.abs(left-right)>1) return -1;
return Math.max(left,right)+1;
}
}


View Code
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: