天天看点

UOJ 买卖最大化利润

Problem description:

UOJ 买卖最大化利润

Solution:

def maxProfit(self, prices: List[int]) -> int:
        #return sum(y-x for y,x in zip(prices[1:],prices[:-1]) if y-x>0)
        if len(prices)<1:
            return 0
        buyPrice,res = prices[0],0
        for price in prices:
            if price>=buyPrice:
                res+=price - buyPrice
                buyPrice = price
            else:
                buyPrice = price
        return res
           

继续阅读