123 Best Time to Buy and Sell Stock III
1. Question
Say you have an array for which thei_thelement is the price of a given stock on day_i.
Design an algorithm to find the maximum profit. You may complete at most_two_transactions.
Note: You may not engage in multiple transactions at the same time (i.e., you must sell the stock before you buy again).
Example 1:
Example 2:
Example 3:
2. Implementation
(1) DP
思路: 188的简化版,参考188即可
3. Time & Space Complexity
DP: 时间复杂度O(n), 空间复杂度O(n)
Last updated
Was this helpful?