7 line JavaScript solution with DP


  • 0
    L
    function maxSubArray(nums) {
        var sum = 0;
        return nums.reduce((max, curr) => {
            sum = curr + (sum > 0 ? sum : 0);
            return Math.max(max, sum);
        }, -Number.MAX_VALUE);
    }

Log in to reply
 

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