123. Best Time to Buy and Sell Stock III
https://leetcode.com/problems/best-time-to-buy-and-sell-stock-iii/
class Solution:
def maxProfit(self, prices: List[int]) -> int:
maxProfit1 = 0
maxProfit2 = 0
minCost1 = float("inf")
minCost2 = float("inf")
for price in prices:
maxProfit1 = max(maxProfit1,price-minCost1)
minCost1 = min(price,minCost1)
maxProfit2 = max(maxProfit2, price-minCost2)
minCost2 = min(minCost2,price-maxProfit1)
return maxProfit2Previous122. Best Time to Buy and Sell Stock IINext309. Best Time to Buy and Sell Stock with Cooldown
Last updated