C++ O(1) time solution, 0ms


  • -1
    Y
    int integerBreak (int n) {
        if(n==2 || n==3)
            return n-1;
            
        int num3=0,num2=0;
        if(n%3==1){
            num3=(n-4)/3;
            num2=2;
        }
        else if(n%3==2){
            num3=n/3;
            num2=1;
        }
        else{
            num3=n/3;
        }
        long long result=pow(3,num3)*pow(2,num2);
        return result;
    }

Log in to reply
 

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