Files
leetcode/0122-best-time-to-buy-and-sell-stock-ii/0122-best-time-to-buy-and-sell-stock-ii.py
T

12 lines
300 B
Python

class Solution:
def maxProfit(self, prices: List[int]) -> int:
profit = 0
for i in range(len(prices) - 1):
before = prices[i]
after = prices[i + 1]
if before < after:
profit += after - before
return profit