数据结构与算法之买卖股票的最佳时机II

问题

在这里插入图片描述

解答

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

击败用户

在这里插入图片描述

发布了25 篇原创文章 · 获赞 8 · 访问量 918

猜你喜欢

转载自blog.csdn.net/weixin_44617944/article/details/104657175