From dff49256e54349f86aff0d9dcbde914d0afb7245 Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 24 Oct 2017 21:08:11 -0400 Subject: [PATCH] Simplify loop in max profit challenge (#214) --- online_judges/max_profit/max_profit_solution.ipynb | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/online_judges/max_profit/max_profit_solution.ipynb b/online_judges/max_profit/max_profit_solution.ipynb index 933249d..6577016 100644 --- a/online_judges/max_profit/max_profit_solution.ipynb +++ b/online_judges/max_profit/max_profit_solution.ipynb @@ -105,11 +105,9 @@ " raise TypeError('prices cannot be None')\n", " if len(prices) < 2:\n", " raise ValueError('prices must have at least two values')\n", - " min_price = prices[0]\n", - " max_profit = -sys.maxsize\n", - " for index, price in enumerate(prices):\n", - " if index == 0:\n", - " continue\n", + " min_price = prices.pop(0)\n", + " max_profit = prices[0] - min_price\n", + " for price in prices:\n", " profit = price - min_price\n", " min_price = min(price, min_price)\n", " max_profit = max(profit, max_profit)\n",