src/com/michaelho/DivideAndConquer/DC1.java
/**
     * Calculate multiplication using naive approach which is less efficient.
     * Runtime: O(N^2)
     * LeetCode: https://leetcode.com/problems/multiply-strings/
     *
     * @param x The first number.
     * @param y The second number.
     *
     * @return The calculation result.
     * */
Calculate multiplication using naive approach which is less efficient.

@param x The first number.
@param y The second number.

@return The calculation result.
Calculate multiplication using naive approach which is less efficient . @param x The first number . @param y The second number . @return The calculation result .
int calculateByNaiveApproach(int x, int y) {
        String num1 = new StringBuilder(Integer.toString(x)).reverse().toString();
        String num2 = new StringBuilder(Integer.toString(y)).reverse().toString();
        String output = "";
        for (int idx1 = 0; idx1 < num1.length(); idx1++) {
            for (int idx2 = 0; idx2 < num2.length(); idx2++) {
                int val = Integer.valueOf(num1.substring(idx1, idx1+1))*Integer.valueOf(num2.substring(idx2, idx2+1));
                output = addDecimal(idx1+idx2, val, output);
            }
        }
        return Integer.valueOf(new StringBuilder(output).reverse().toString());
    }
int calculateByNaiveApproach ( int x , int y ) { String num1 = new StringBuilder ( Integer . toString ( x ) ) . reverse ( ) . toString ( ) ; String num2 = new StringBuilder ( Integer . toString ( y ) ) . reverse ( ) . toString ( ) ; String output = "" ; for ( int idx1 = 0 ; idx1 < num1 . length ( ) ; idx1 ++ ) { for ( int idx2 = 0 ; idx2 < num2 . length ( ) ; idx2 ++ ) { int val = Integer . valueOf ( num1 . substring ( idx1 , idx1 + 1 ) ) * Integer . valueOf ( num2 . substring ( idx2 , idx2 + 1 ) ) ; output = addDecimal ( idx1 + idx2 , val , output ) ; } } return Integer . valueOf ( new StringBuilder ( output ) . reverse ( ) . toString ( ) ) ; }
Calculate multiplication using naive approach which is less efficient.
Calculate multiplication using naive approach which is less efficient .