
/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
public class Solution {
public int getDepth(TreeNode root, int curDepth){
if(root==null) return curDepth;
return Math.max(getDepth(root.left,curDepth+1),getDepth(root.right,curDepth+1));
}
public boolean isBalanced(TreeNode root) {
if(root==null) return true;
int left = getDepth(root.left,1);
int right = getDepth(root.right,1);
if(Math.abs(left-right)>1){
return false;
}else{
return isBalanced(root.left) && isBalanced(root.right);
}
}
}