Series of problems related to "Best Time to Buy and Sell Stock"
We could solve these problems using the same concept, Final State Machine. Only two states are required for us to come up with the solution:
Hold State - The profit when we hold the stock. It could indicate that we already hold the stock and don't sell it or just buy a stock.
No-hold State - The profit when we don't hold the stock. It could indicate that we haven't bought any stocks or just sell a stock.
Note that we could decide not to perform any actions (either buy or sell) in a certain day if we cannot gain more profits.
Related problems (follow the order to solve each problem):
0122. Best Time to Buy and Sell Stock IIarrow-up-right
0714. Best Time to Buy and Sell Stock with Transaction Feearrow-up-right
0121. Best Time to Buy and Sell Stockarrow-up-right
0309. Best Time to Buy and Sell Stock with Cooldownarrow-up-right
0123. Best Time to Buy and Sell Stock IIIarrow-up-right
0188. Best Time to Buy and Sell Stock IVarrow-up-right (Same solution as 0123)
Last updated 4 years ago