题解 | #买卖股票的最好时机(一)#
买卖股票的最好时机(一)
https://www.nowcoder.com/practice/64b4262d4e6d4f6181cd45446a5821ec
package main /** * * @param prices int整型一维数组 * @return int整型 */ func maxProfit( prices []int ) int { res := 0 preMi := 0 for i,val := range prices { if i > 0 && val - preMi > res { res = val - preMi } if i == 0 || val < preMi { preMi = val } } return res // write code here }