121. 买卖股票的最佳时机

func maxProfit(prices []int) int {

    max := 0
    left := 0
    for i:=0; i<len(prices); i++ {
        dif := prices[i]-prices[left]
        if dif > max {
            max = dif
        }
        if dif < 0 {
            left = i 
        }
    }
    return max
}
posted @ 2024-06-07 15:25  gdut17_2  阅读(13)  评论(0)    收藏  举报