Answers for "leetcode 122 best stock 2"

0

leetcode 122 best stock 2

class Solution:
    def maxProfit(self, prices: List[int]) -> int:
        size = len(prices)

        ans = 0
        for i in range(1, size):
            # This only calculates the accumulation profit in the case of existence of profits
            #            
            ans += max(0, prices[i]-prices[i-1])
        
        return ans
1234567891011
Posted by: Guest on August-23-2021

Browse Popular Code Answers by Language