leetcode.122买卖股票的最佳时机II

题目不限定买卖次数


class Solution:
    def maxProfit(self, prices: List[int]) -> int:
        ans=0
        for i in range(len(prices)-1):
            v=prices[i+1]-prices[i]
            ans+=v if v>0 else 0
        return ans

猜你喜欢

转载自www.cnblogs.com/liguitar/p/11520539.html