2019-02-11 algorithm leetcode -maxSubArray Leetcode题解之 —— 最大子序和 思路 动态规划 Math.max更新最大值 更新currentSum, 即当前序列和 题解 12345678910111213141516/** * @param {number[]} nums * @return {number} */var maxSubArray = function(nums) { let [maxSum, currentSum] = [-Number.MAX_VALUE, 0]; for (const value of nums) { currentSum += value; maxSum = Math.max(currentSum, maxSum); currentSum = currentSum < 0 ? 0 : currentSum; } return maxSum;}; 作者 : zhaoyang Duan 地址 : https://ddzy.github.io/blog/2019/02/11/leetcode-maxSubArray/ 来源 : https://ddzy.github.io/blog 著作权归作者所有,转载请联系作者获得授权。