110. Balanced Binary Tree
1 class Solution { 2 public boolean isBalanced(TreeNode root) { 3 if(root == null) return true; 4 return(isBalanced(root.left) && isBalanced(root.right) && Math.abs(dfs(root.left) - dfs(root.right)) > 1); 5 6 } 7 8 public int dfs(TreeNode root) { 9 if(root == null) return 0; 10 return (Math.max(dfs(root.left), dfs(root.right))+1); 11 12 } 13 }