From de7b15c917055e752c603933bebd169d06760580 Mon Sep 17 00:00:00 2001 From: bumpsoo Date: Fri, 9 May 2025 15:23:03 +0000 Subject: [PATCH] https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii --- medium/best_time_to_buy_and_sell_stock_ii.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 medium/best_time_to_buy_and_sell_stock_ii.py diff --git a/medium/best_time_to_buy_and_sell_stock_ii.py b/medium/best_time_to_buy_and_sell_stock_ii.py new file mode 100644 index 0000000..09fc939 --- /dev/null +++ b/medium/best_time_to_buy_and_sell_stock_ii.py @@ -0,0 +1,13 @@ +# https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii + +from typing import List + +class Solution: + def maxProfit(self, prices: List[int]) -> int: + result = 0 + last = prices[0] + for i in range(1, len(prices)): + if last < prices[i]: + result += prices[i] - last + last = prices[i] + return result