python-leetcode-买卖股票的最佳时机 II

122. 买卖股票的最佳时机 II - 力扣(LeetCode)

python 复制代码
class Solution:
    def maxProfit(self, prices: List[int]) -> int:
        max_profit = 0  # 初始化最大利润为0
        for i in range(1, len(prices)):
            if prices[i] > prices[i - 1]:
                max_profit += prices[i] - prices[i - 1]  # 累加利润

        return max_profit
相关推荐
KaMeidebaby38 分钟前
卡梅德生物技术快报|小 RNA 适配体合成 + 多方法亲和力表征全流程标准化操作手册
前端·网络·数据库·人工智能·算法
是Dream呀38 分钟前
基于深度学习的人类行为识别算法研究
人工智能·深度学习·算法
happyprince1 小时前
03_NVIDIA_ModelOpt-量化算法深入
人工智能·深度学习·算法
大鱼>2 小时前
AI+货物追踪:智能快递柜追踪系统
人工智能·深度学习·算法·机器学习
researcher-Jiang2 小时前
算法训练:堆 & 可并堆
算法
在书中成长2 小时前
HarmonyOS 小游戏《对战五子棋》开发第18篇 - 棋盘设计
算法·harmonyos
Frostnova丶2 小时前
(12)LeetCode 76. 最小覆盖子串
算法·leetcode·职场和发展
灯澜忆梦3 小时前
GO_函数_1
算法
旧曲重听13 小时前
为什么现在 RAG 越少越少提及了
数据库·程序人生·职场和发展·agent
言乐63 小时前
Python实现建造微服务商城后台
开发语言·python·算法·微服务·架构