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
}
相关推荐
数据分析螺丝钉38 分钟前
力扣第240题“搜索二维矩阵 II”
经验分享·python·算法·leetcode·面试
￴ㅤ￴￴ㅤ9527超级帅39 分钟前
LeetCode hot100---数组及矩阵专题(C++语言)
c++·leetcode·矩阵
吃着火锅x唱着歌1 小时前
Redis设计与实现 学习笔记 第五章 跳跃表
golang
鱼跃鹰飞1 小时前
Leecode热题100-295.数据流中的中位数
java·服务器·开发语言·前端·算法·leetcode·面试
技术卷4 小时前
Redis数据库与GO完结篇:redis操作总结与GO使用redis
数据库·redis·golang
源代码•宸4 小时前
Leetcode—76. 最小覆盖子串【困难】
c++·经验分享·算法·leetcode·滑动窗口
百里守约学编程5 小时前
70. 爬楼梯
算法·leetcode·go
white.tie7 小时前
vscode配置golang
ide·vscode·golang
陈序缘7 小时前
Go语言实现长连接并发框架 - 任务管理器
linux·服务器·开发语言·后端·golang
Mephisto.java11 小时前
【力扣 | SQL题 | 每日四题】力扣1783,1757,1747,1623,1468,1661
算法·leetcode