309. Best Time to Buy and Sell Stock with Cooldown

T: O(n)

S: O(1)

time: O(n)

space: O(n)

這題沒有限制交易次數, 所以跟 II 類似, 但有冷卻期的限制

  • After you sell your stock, you cannot buy stock on the next day (i.e., cooldown one day).

因此,如果要在第i天買入股票,第二個狀態轉移方程中就不能使用T[i - 1][k][0],而應該使用T[i - 2][k][0]

use variables

time: O(n)

space: O(1)

Last updated

Was this helpful?