class Solution {
public boolean isBalanced(TreeNode root) {
if(root == null) return true;
if(Math.abs(treeDepth(root.left) - treeDepth(root.right)) > 1) return false;
return isBalanced(root.left) && isBalanced(root.right);
}
private int treeDepth(TreeNode root){
if(root == null) return 0;
return Math.max(treeDepth(root.left), treeDepth(root.right)) + 1;
}
}
睿总