Simplify loop in max profit challenge (#214)

This commit is contained in:
Michael 2017-10-24 21:08:11 -04:00 committed by Donne Martin
parent 2865bdcf94
commit dff49256e5

View File

@ -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",