Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution:
- def maxProfit(self, prices: List[int]) -> int:
- """
- max_current_profit is either obtained by immediately adding current_profit at current index (2) to max_current_profit
- max_current_profit is either obtained by current profit
- """
- max_current_profit = 0
- max_profit_so_far = 0
- for i in range(1, len(prices)):
- max_current_profit = max(
- prices[i] - prices[i-1],
- max_current_profit + (prices[i] - prices[i-1])
- )
- max_profit_so_far = max(max_profit_so_far, max_current_profit)
- return max_profit_so_far
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement