mirror of
https://github.com/ShusenTang/LeetCode.git
synced 2024-09-02 14:20:01 +00:00
update: add blog link
This commit is contained in:
parent
de56b16604
commit
6f92b2ca78
@ -1,4 +1,6 @@
|
|||||||
# [121. Best Time to Buy and Sell Stock](https://leetcode.com/problems/best-time-to-buy-and-sell-stock/description/)
|
# [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中,prices[i]-prices[j]的最大值,其中i > j。
|
||||||
因此prices[j]肯定是prices[i]之前的元素中最小的那一个,所以从前往后遍历,并用min_price记录当前位置前的元素中最小的一个。
|
因此prices[j]肯定是prices[i]之前的元素中最小的那一个,所以从前往后遍历,并用min_price记录当前位置前的元素中最小的一个。
|
||||||
|
@ -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/)
|
# [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天的最大利润就为:
|
如果分别知道了前0到前i天的最大利润dp[0...i],那么前i+1天的最大利润就为:
|
||||||
|
Loading…
Reference in New Issue
Block a user