8.23笔记

376. 摆动序列

class Solution(object):
    def wiggleMaxLength(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        if len(nums)<2:
          return len(nums)
        up,down = 1,1
        for i in range(1,len(nums)):
          if nums[i] - nums[i-1] > 0:
            up = down + 1
          if nums[i] - nums[i-1] < 0:
            down = up + 1
        return max(up,down)

714. 买卖股票的最佳时机含手续费(贪心)

class Solution(object):
    def maxProfit(self, prices, fee):
        """
        :type prices: List[int]
        :type fee: int
        :rtype: int
        """
        mi = prices[0]
        n = len(prices)
        res = 0
        for i in range(1,n):
          if prices[i] < mi:
            mi = prices[i]
          elif prices[i] > mi+fee:
            res += prices[i]-mi-fee
            mi = prices[i]-fee
        return res

 

上一篇:万万没想到之抓捕孔连顺


下一篇:jzoj 6273. 2019.8.4【NOIP提高组A】欠钱 (money)