多看书!多看讨论!多看题解!!!
多看书!多看讨论!多看题解!!!
多看书!多看讨论!多看题解!!!
// 同一个思路,写出来的代码差距太大了,膜拜ORZ
public class Solution {
public int getDepth(TreeNode root) {
if (root == null) {
return 0;
}
int left = getDepth(root.left);
if (left == -1) return -1;
int right = getDepth(root.right);
if (right == -1) return -1;
return Math.abs(left - right) > 1 ? -1 : 1 + Math.max(left, right);
}
public boolean IsBalanced_Solution(TreeNode root) {
return getDepth(root) != -1;
}
}

京公网安备 11010502036488号