Python Greedy
The heuristic is that as long as current price is higher than previous lowest price, max profit could be updated. So I use buy to track previous lowest price (i
The heuristic is that as long as current price is higher than previous lowest price, max profit could be updated. So I use ```buy``` to track previous lowest price (indicating we can buy in that time) and ```ans``` to track max profit we have achieved so far.\n```\ndef maxProfit(prices):\n\tbuy, ans = float(\'inf\'), 0\n\tfor p in prices:\n\t\tbuy, ans = min(buy, p), max(ans, p-buy)\n\treturn ans\n```
['Python']