LeetCode122 买卖股票的最佳时机 II(贪心)

LeetCode122 买卖股票的最佳时机 II

贪心计算爬峰收益

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

        ans, l = 0, len(prices)
        for i in range(1, l): ans += max(0, prices[i] - prices[i - 1])

        return ans

posted on 2022-06-29 13:29  solvit  阅读(28)  评论(0)    收藏  举报

导航