func maxProfit(prices []int) int { res, low := 0, prices[0] for _, price := range prices { if price < low { low = price } res = max(res, price - low) } return res }
O(n)
O(1)