diff --git a/solutions/121. Best Time to Buy and Sell Stock.md b/solutions/121. Best Time to Buy and Sell Stock.md index b2ee9a5..584a002 100644 --- a/solutions/121. Best Time to Buy and Sell Stock.md +++ b/solutions/121. Best Time to Buy and Sell Stock.md @@ -1,4 +1,6 @@ # [121. Best Time to Buy and Sell Stock](https://leetcode.com/problems/best-time-to-buy-and-sell-stock/description/) + +update: LeetCode六道股票买卖题目总结见我的博客文章[动态规划之股票买卖系列](https://shusentang.github.io/2019/11/03/Buy-and-Sell-Stock/) # 思路 题目的意思就是求数组prices中,prices[i]-prices[j]的最大值,其中i > j。 因此prices[j]肯定是prices[i]之前的元素中最小的那一个,所以从前往后遍历,并用min_price记录当前位置前的元素中最小的一个。 diff --git a/solutions/122. Best Time to Buy and Sell Stock II.md b/solutions/122. Best Time to Buy and Sell Stock II.md index f6fbf90..d792b9e 100644 --- a/solutions/122. Best Time to Buy and Sell Stock II.md +++ b/solutions/122. Best Time to Buy and Sell Stock II.md @@ -1,4 +1,7 @@ # [122. Best Time to Buy and Sell Stock II](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii/description/) + +update: LeetCode六道股票买卖题目总结见我的博客文章[动态规划之股票买卖系列](https://shusentang.github.io/2019/11/03/Buy-and-Sell-Stock/) + # 思路 ## 比较好想的思路 如果分别知道了前0到前i天的最大利润dp[0...i],那么前i+1天的最大利润就为: