1、最大连续子数组
https://leetcode-cn.com/problems/lian-xu-zi-shu-zu-de-zui-da-he-lcof/solution/jian-dan-dp-by-1nxctrvewn-itv5/
dp[i] 代表到i时的最大子序列的值,由dp[i-1] + 当前值 和当前值相比
(如果当前值大于前子序列+当前值,那么当前值就是最大子序列)
var maxSubArray = function(nums) {if (!nums.length) returnlet max_here = nums[0]let max_so_far = nums[0]for (let i = 1; i < nums.length; i++) {max_here = Math.max(nums[i], max_here + nums[i])max_so_far = Math.max(max_here, max_so_far)}return max_so_far};
2、股票的最大利润
https://leetcode-cn.com/problems/gu-piao-de-zui-da-li-run-lcof/solution/
var maxProfit = function(prices) {let min = Number.MAX_VALUElet max = 0for (let p of prices) {max = Math.max(p - min, max)min = Math.min(min, p)}return max};
