func maxProfit(prices []int) int { // 最大利润=第i天卖出-最小买入 var min_input = prices[0]//默认第0天为最小买入 var max_profit = 0//最大利润 for i:=1;i<len(prices);i++{ min_input = min(min_input, prices[i]) max_profit = max(max_profit, prices[i]-min_input) } return max_profit } func max(a, b int)int{ if a>=b{ return a } return b } func min(a, b int)int{ if a<=b{ return a } return b }