diff --git a/Algorithms/Easy/121_BestTimeToBuyAndSellStock/Solution.py b/Algorithms/Easy/121_BestTimeToBuyAndSellStock/Solution.py new file mode 100644 index 0000000..8cfce26 --- /dev/null +++ b/Algorithms/Easy/121_BestTimeToBuyAndSellStock/Solution.py @@ -0,0 +1,15 @@ +class Solution: + def maxProfit(self, prices: List[int]) -> int: + left = 0 + right = 1 + max_profit = 0 + + while right < len(prices): + if prices[right] < prices[left]: + left = right + right += 1 + else: + max_profit = max(max_profit, prices[right] - prices[left]) + right += 1 + + return max_profit \ No newline at end of file