这个题目总共能买卖两次,且必须要先卖掉第一次才能买第二次的,所以可以从左往右扫描获得 [0, i] 的最大盈利,从右往左扫描 [i, n-1] 的最大盈利,然后 left[i] + right[i] 的最大值就是两次购买的最大盈利了。func maxProfit(prices []int) int { n := len(prices) minLeft := prices[0]...
这个题目总共能买卖两次,且必须要先卖掉第一次才能买第二次的,所以可以从左往右扫描获得 [0, i] 的最大盈利,从右往左扫描 [i, n-1] 的最大盈利,然后 left[i] + right[i] 的最大值就是两次购买的最大盈利了。func maxProfit(prices []int) int { n := len(prices) minLeft := prices[0]...