双重递归(利用上一题的结果)
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);
}
}
京公网安备 11010502036488号