#
# 
# @param prices int整型一维数组 
# @return int整型
#基本思路:假设当前a最小,当遇到b(b<a)时,我们可知:若后面出现的使得利益更大的价格C 
#(max利润=C-a),那么C-b一定大于C-a,即后面的最大收益的比较只需要通过b来计算
#(max利润=C-b),不再需要a了,因此,我们需要一个游标来记录和更新min值。
class Solution:
    def maxProfit(self , prices ):
        # write code here
        min_=float("inf")
        max_=0
        for i in range(len(prices)):
            min_=min(min_,prices[i])
            max_=max(max_,prices[i]-min_)
        return max_