您的位置:首页 > 其它

[LeetCode]Balanced Binary Tree

2015-12-01 15:28 337 查看
public class Solution {
boolean result = true;
public boolean isBalanced(TreeNode root) {
helper(root);
return result;
}
public int helper(TreeNode root) {
if (root == null) {
return 0;
}
int left = helper(root.left);
int right = helper(root.right);
if (Math.abs(left - right) > 1) {
result = false;
return -1;
} else {
return Math.max(left, right) + 1;
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: