C++ optimal (?) in O(n)


  • 0
    4
    int integerBreak( int n )
    {
        if( n < 4 ) return n - 1;
        int first = n % 3;
        if( first != 2 ) first += 3;
        return first * pow( 3, ( n - 2 ) / 3);
    }
    

    Pow is hardware specific function; we should NOT assume that its runtime is constant.

    This problem should have easy difficulty.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.