No DP required, Simple Java Solution, 0 ms


  • 2

    Based on the concept that if a number is >4 we can break it into number of 3's and the product of 3's are always greater. 3333 > 44*4 for n=12

    public int integerBreak(int n) {
            if(n==2)return 1;
            if(n==3) return 2;
            int result=1;
            while(n>=3 && n!=4){
                result*=3;
                n-=3;
            }
            if(n==4 || n==2){
                result*=n;
            }
            return result;
        }
    

Log in to reply
 

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