From 57954bc01adbd9291cc8c7395db77c930a6a046f Mon Sep 17 00:00:00 2001 From: "Sachdeva, Kapil" Date: Thu, 2 Jan 2025 08:44:24 -0600 Subject: [PATCH] fix - an example of how to use types and correct casing for functions --- .../easy/best_time_to_buy_and_sell_stock.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/problems/solved/easy/best_time_to_buy_and_sell_stock.py b/problems/solved/easy/best_time_to_buy_and_sell_stock.py index 81f87fc..b4006e4 100644 --- a/problems/solved/easy/best_time_to_buy_and_sell_stock.py +++ b/problems/solved/easy/best_time_to_buy_and_sell_stock.py @@ -1,15 +1,13 @@ -def maxProfit(prices): - """ - :type prices: List[int] - :rtype: int - """ +"""Compute the maximum profit that can be obtained by buying and selling a stock at most once.""" + +def compute_max_profit(prices: list[int]) -> int: length = len(prices) total_profit = 0 max_profit = 0 - for i in range(length-1): - marginal_profit = prices[i+1] - prices[i] + for i in range(length - 1): + marginal_profit = prices[i + 1] - prices[i] total_profit = total_profit + marginal_profit if total_profit < 0: total_profit = 0 @@ -17,5 +15,6 @@ def maxProfit(prices): return max_profit -print(maxProfit([7,1,5,3,6,4])) -print(maxProfit([7,6,4,3,1])) \ No newline at end of file + +print(compute_max_profit([7, 1, 5, 3, 6, 4])) +print(compute_max_profit([7, 6, 4, 3, 1]))