this is much easier to understand than pattern


  • 0
    J
    class Solution {
    public:
        int integerBreak(int n) {
            vector<int>dp(n+1,INT_MIN);
            dp[1] = 1;
            for(int i=2;i<=n;i++)
            {
                for(int j = 1;j<i;j++)
                    dp[i] = max(dp[i],max(j,dp[j])*max(i-j,dp[i-j]));
            }
            return dp[n];
        }
    };
    

Log in to reply
 

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