121.Best Time to Buy and Sell Stock I
和leetcode 53类似,用一个变量来记录子问题的最小值。
122.Best Time to Buy and Sell Stock II
贪心,只要这天比前一天高就抛售 lol
123.Best Time to Buy and Sell Stock III
DP的解法 two pass
188.Best Time to Buy and Sell Stock IV
这个印度小哥讲的不错。
Youtube
状态转移方程
dp[i][j] = max(dp[i][j-1],
for m ~ (0,j) find max( dp[i-1][m] + prices[j] - prices[m])
|
|
309.Best Time to buy and Sell stock with cooldown