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
相关推荐
黎阳之光14 小时前
全域实景立体管控:数字孪生与视频孪生技术体系白皮书
大数据·人工智能·算法·安全·数字孪生
88号技师14 小时前
2026年4月一区SCI-狒狒优化算法Baboon optimization algorithm-附Matlab免费代码
开发语言·算法·数学建模·matlab·优化算法
凯瑟琳.奥古斯特15 小时前
BFS解力扣1654最短跳跃次数
数据结构·算法·广度优先
sg_knight15 小时前
第一次用 OpenClaw,我让它 3 分钟写了个小工具
算法·llm·agent·ai编程·openclaw
m0_6294947315 小时前
LeetCode 热题 100-----23.反转链表
数据结构·算法·leetcode·链表
炸膛坦客15 小时前
嵌入式 - 数据结构与算法:(1-10)排序算法 - 冒泡排序(Bubble Sort)
算法·排序算法
Hello eveybody15 小时前
介绍一下动态树LCT(Python)
开发语言·python·算法
不穿铠甲的穿山甲15 小时前
MMR最大边际相关性
算法
handler0115 小时前
速通蓝桥杯省一:二分算法
c语言·开发语言·c++·笔记·算法·职场和发展·蓝桥杯
炽烈小老头15 小时前
【 每天学习一点算法 2026/05/08】最小覆盖子串
学习·算法