src/com/michaelho/DynamicProgramming/DP2.java
/**
     * The method is used to determine if the binary tree is balanced. The definition of
     * a balanced binary tree means that each two subtrees of a root has the height difference
     * of 1 or less.
     *
     * @param root The root node of the binary tree.
     * @return The boolean indicates if the tree is balanced.
     * */
The method is used to determine if the binary tree is balanced. The definition of
a balanced binary tree means that each two subtrees of a root has the height difference
of 1 or less.

@param root The root node of the binary tree.
@return The boolean indicates if the tree is balanced.
The method is used to determine if the binary tree is balanced . The definition of a balanced binary tree means that each two subtrees of a root has the height difference of 1 or less . @param root The root node of the binary tree . @return The boolean indicates if the tree is balanced .
boolean isBalancedBinaryTree(TreeNode root) {
        if (root == null)
            return true;
        int leftHeight = getTreeHeight(root.left);
        int rightHeight = getTreeHeight(root.right);
        return Math.abs(leftHeight - rightHeight) <= 1
                && isBalancedBinaryTree(root.left)
                && isBalancedBinaryTree(root.right);
    }
boolean isBalancedBinaryTree ( TreeNode root ) { if ( root == null ) return true ; int leftHeight = getTreeHeight ( root . left ) ; int rightHeight = getTreeHeight ( root . right ) ; return Math . abs ( leftHeight - rightHeight ) <= 1 && isBalancedBinaryTree ( root . left ) && isBalancedBinaryTree ( root . right ) ; }
The method is used to determine if the binary tree is balanced.
The method is used to determine if the binary tree is balanced .