class Solution:
    def maxProfit(self, prices: List[int]) -> int:
        if prices == []:
            return 0
        min = prices[0]
        max_num = 0
        for i in range(len(prices)):
            if prices[i] < min:
                min = prices[i]
            max_num = max(max_num, prices[i]-min )
        return max_num

 

class Solution:
    def maxProfit(self, prices: List[int]) -> int:
        if prices == []:
            return 0
        min = prices[0]
        max_num = 0
        #空间节省了,当时时间却增多了
        for i in range(1,len(prices)):
            if prices[i] < min:
                min = prices[i]
            max_num = max(max_num, prices[i]-min )
        return max_num

 

posted on 2020-04-05 09:22  topass123  阅读(118)  评论(0编辑  收藏  举报