DP Javascript solution


  • 0
    L
    function integerBreak(n) {
        var arr = [0, 1];
        for (var i = 2; i <= n; i++) {
            arr[i] = 0;
            // exclusive
            for (var j = 1; j < i; j++) {
                arr[i] = Math.max(arr[i], arr[j] * (i - j), j * (i - j));
            }
        }
        return arr[n];
    }

Log in to reply
 

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