Share accepted java solution


  • 0
    M

    I share my solution which doesn't have a fancy theory.
    I did it by a trial and error methodology

    I learned a lot from hot solutions. Great job guys.!

    public int integerBreak(int n) {
        
        int max = 0;
        
        for(int i=1;i<=3 && i<n;i++){
            int power = n/i;
            
            if(n%i == 1 && i+n%i < n){
                max = Math.max(max, (int)Math.pow(i,power-1) * (i+n%i));
            }else{
                max = Math.max(max, (int)Math.pow(i,power)*((n%i)==0?1:n%i));
            }
        }
        return max;
    }

Log in to reply
 

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