美文网首页
2020-04-13 Day 51 Leetcode: 121.

2020-04-13 Day 51 Leetcode: 121.

作者: YueTan | 来源:发表于2020-04-13 08:43 被阅读0次
    class Solution:
        def maxProfit(self, prices: List[int]) -> int:
            if not prices:
                return 0
            pre_min=[prices[0]]
            for i in range(1,len(prices)):
                pre_min.append(min(prices[:i]))
            
            profit=[0]
            for i in range(1,len(prices)):
                profit.append(prices[i]-pre_min[i])
            return max(profit)
    

    相关文章

      网友评论

          本文标题:2020-04-13 Day 51 Leetcode: 121.

          本文链接:https://www.haomeiwen.com/subject/rvmwmhtx.html