/**
* Definition for binary tree
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
public class Solution {
private int treeDepth(TreeNode root){
if(root == null)
return 0;
return 1 + Math.max(treeDepth(root.left), treeDepth(root.right));
}
public boolean isBalanced(TreeNode root) {
if(null == root)
return true;
if(Math.abs(treeDepth(root.left) - treeDepth(root.right)) <= 1)
return isBalanced(root.left) && isBalanced(root.right);
return false;
}
}
07-23
07-23