(TreeNode root)
| 13 | } |
| 14 | |
| 15 | public static boolean isBalanced(TreeNode root) { |
| 16 | if (root == null) { |
| 17 | return true; |
| 18 | } |
| 19 | int heightDiff = getHeight(root.left) - getHeight(root.right); |
| 20 | if (Math.abs(heightDiff) > 1) { |
| 21 | return false; |
| 22 | } |
| 23 | else { |
| 24 | return isBalanced(root.left) && isBalanced(root.right); |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | public static void main(String[] args) { |
| 29 | // Create balanced tree |