Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution:
- def maxProfit(self, prices: List[int]) -> int:
- result = 0
- buy_idx = 0
- sell_idx = 0
- for i in range(1, len(prices)):
- if prices[i] >= prices[sell_idx]:
- sell_idx = i
- else:
- if sell_idx > buy_idx:
- result += prices[sell_idx] - prices[buy_idx]
- sell_idx = buy_idx = i
- if sell_idx > buy_idx:
- result += prices[sell_idx] - prices[buy_idx]
- return result
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement