The best time to buy and sell stocks leetcode.122 II

Topic is not limited to the number of trading


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

Guess you like

Origin www.cnblogs.com/liguitar/p/11520539.html