剑指offer 二叉平衡树
平衡二叉树
http://www.nowcoder.com/questionTerminal/8b3b95850edb4115918ecebdf1b4d222
双重递归(利用上一题的结果)
public class Solution {
public int TreeDepth(TreeNode root) {
if (root == null) return 0;
return 1 + Math.max(TreeDepth(root.left), TreeDepth(root.right));
}
public boolean IsBalanced_Solution(TreeNode root) {
if (root == null) return true;
return Math.abs(TreeDepth(root.left) - TreeDepth(root.right)) <= 1
&& IsBalanced_Solution(root.left)
&& IsBalanced_Solution(root.right);
}
}
查看13道真题和解析