My Dp Solution


  • 0
    B
     public int integerBreak(int n) {
            if (n <= 1) return 0;
            int[][] dp = new int[n + 1][n + 1];
            dp[0][1] =1;
            for (int i = 1; i <= n; i++) {
                for (int j = 1; j <= n; j++) {
                    if (j < i) {
                        dp[i][j] = dp[i-1][j];
                    } else {
                        dp[i][j] = Math.max(dp[i - 1][j],
                                Math.max(dp[i][j - i], j - i) *
                                        Math.max(dp[i][i], i));
                    }
                }
            }
            return dp[n][n];
        }
    

Log in to reply
 

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