Golang | Leetcode Golang题解之第122题买卖股票的最佳时机II

题目:

题解:

Go 复制代码
func maxProfit(prices []int) (ans int) {
    for i := 1; i < len(prices); i++ {
        ans += max(0, prices[i]-prices[i-1])
    }
    return
}

func max(a, b int) int {
    if a > b {
        return a
    }
    return b
}
相关推荐
硕风和炜9 小时前
【LeetCode: 2492. 两个城市间路径的最小分数 + DFS】
java·算法·leetcode·深度优先·dfs·bfs·并查集
凯瑟琳.奥古斯特11 小时前
K次取反最大化数组和解法(力扣1005)
开发语言·c++·算法·leetcode·职场和发展
tachibana213 小时前
hot100 回文链表(234)
java·网络·数据结构·leetcode·链表
wabs66616 小时前
关于动态规划【力扣1143.最长公共子序列的思考】
算法·leetcode·动态规划
剑挑星河月16 小时前
54.螺旋矩阵
java·算法·leetcode·矩阵
笨笨没好名字17 小时前
Leetcode刷题python3版第一周(下)
linux·算法·leetcode
想你依然心痛18 小时前
AtomCode在后端开发中的实战体验:Go微服务从零搭建
开发语言·微服务·golang
王老师青少年编程18 小时前
2026年6月GESP真题及题解(C++五级):排排坐
c++·题解·真题·gesp·五级·2026年6月·排排坐
开发小程序的之朴19 小时前
认识安企CMS - 系统概述
nginx·golang·系统架构
雨师@19 小时前
go语言项目--实例化(图书管理)--005
开发语言·后端·golang