diff --git a/0122-best-time-to-buy-and-sell-stock-ii/0122-best-time-to-buy-and-sell-stock-ii.py b/0122-best-time-to-buy-and-sell-stock-ii/0122-best-time-to-buy-and-sell-stock-ii.py new file mode 100644 index 0000000..9ad4bf8 --- /dev/null +++ b/0122-best-time-to-buy-and-sell-stock-ii/0122-best-time-to-buy-and-sell-stock-ii.py @@ -0,0 +1,11 @@ +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