题解 | #牛奶价格预测#

牛奶价格预测

https://www.nowcoder.com/practice/9a08dfa990e94c0c98fd0bf197c87480

#
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
# 
# @param milkPrices int整型一维数组 
# @return int整型
#
class Solution:
    def maxProfit(self , milkPrices: List[int]) -> int:
        # write code here
        if not milkPrices:
            return 0

        max_profit=0
        min_price = milkPrices[0]

        for price in milkPrices:
            min_price = min(min_price, price)
            max_profit = max(max_profit, price - min_price)

        return max_profit

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务