Sunny-117 / js-challenges

✨✨✨ Challenge your JavaScript programming limits step by step

Home Page:https://juejin.cn/column/7244788137410560055

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

最大子数组和

Pcjmy opened this issue · comments

commented
commented

var maxSubArray = function(nums) {
    let dp = [] ;
    dp[0]=nums[0]
    let max = nums[0];
   for(let i =1; i<nums.length ; i++){
        dp[i]=Math.max(dp[i-1]+nums[i],nums[i])
        max=Math.max(dp[i],max)
    }
    return max;
};