维护一个min_,表示是i-1天的最低价格。

#
# 
# @param prices int整型一维数组 
# @return int整型
#
class Solution:
    def maxProfit(self , prices ):
        # write code here
        n = len(prices)
        if n < 2:
            return 0
        min_ = prices[0]
        res =  0
        for i in range(1, n):
            min_ = min(min_, prices[i-1])
            res = max(res,prices[i] - min_)
        return res