Java Math solution without DP


  • 0
    L
    public int integerBreak(int n) {
        int result = 1;
        if(n == 2) return 1;
        if(n == 3) return 2;
        while(n >= 2){
            int num = 3;
            if(n == 4 || n == 2) num = n;
            result *= num;
            n -= num;
        }
        return result;
    }

Log in to reply
 

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