From 987aaf1d298109e1e337b74102dad97a5cc5d362 Mon Sep 17 00:00:00 2001 From: Deven <63876261+devenperez@users.noreply.github.com> Date: Sun, 20 Oct 2024 13:42:31 -0400 Subject: [PATCH] Time: 3 ms (99.17%), Space: 17.4 MB (99.89%) - LeetHub --- .../0122-best-time-to-buy-and-sell-stock-ii.py | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 0122-best-time-to-buy-and-sell-stock-ii/0122-best-time-to-buy-and-sell-stock-ii.py 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