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
}
相关推荐
黑色的山岗在沉睡1 小时前
LeetCode100.4 移动零
数据结构·算法·leetcode
_Itachi__1 小时前
LeetCode 热题 100 114. 二叉树展开为链表
linux·leetcode·链表
全栈凯哥2 小时前
Java详解LeetCode 热题 100(17):LeetCode 41. 缺失的第一个正数(First Missing Positive)详解
java·算法·leetcode
阑梦清川3 小时前
关于Go语言的开发环境的搭建
开发语言·后端·golang
言之。3 小时前
Makefile 在 Go 项目中的实践
开发语言·elasticsearch·golang
MoonBit月兔4 小时前
插件双更新:LeetCode 刷题支持正式上线,JetBrains IDE 插件持续升级!
ide·算法·leetcode
袁气满满~_~6 小时前
LeetCode:617、合并二叉树
算法·leetcode·二叉树
边跑边掩护6 小时前
LeetCode 820 单词的压缩编码题解
算法·leetcode·职场和发展
Espresso Macchiato6 小时前
Leetcode 3543. Maximum Weighted K-Edge Path
leetcode·leetcode medium·图遍历·leetcode 3543·leetcode双周赛156
Clown957 小时前
go-zero(十八)结合Elasticsearch实现高效数据检索
开发语言·elasticsearch·golang