held
, sold
, and reset
arrays with a length of prices.length
and set all values to 0.held[0]
to -prices[0]
to represent buying the stock on the first day.sold[i]
as the profit if selling the stock on day i
.held[i]
as the maximum profit if holding the stock on day i
.reset[i]
as the maximum profit if in cooldown on day i
.sold[n]
and reset[n]
.