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
}
相关推荐
Tisfy2 小时前
LeetCode 3090.每个字符最多出现两次的最长子字符串:二重循环 / 滑动窗口
算法·leetcode·字符串·题解·模拟·双指针·滑动窗口
.道阻且长.5 小时前
8.LeetCode算法习题讲解--滑动窗口--长度最小的子数组
算法·leetcode·职场和发展
wabs6666 小时前
关于字符串【力扣541.反转字符串II的思考】
数据结构·算法·leetcode·字符串
土司大王6 小时前
LeetCode hot100——移动零
java·算法·leetcode
旖旎夜光7 小时前
LeetCode 30:串联所有单词的子串(滑动窗口) —— 题解
数据结构·c++·算法·leetcode·滑动窗口
圣殿骑士-Khtangc8 小时前
Go大厂面试真题精讲之并发安全Map的实现方案
golang
Nil2088 小时前
leetcode 48旋转图像
算法·leetcode·职场和发展
运维开发笔记8 小时前
3.8 Go switch 语句学习笔记
golang
Nil2089 小时前
leetcode 206反转链表
算法·leetcode·链表
Navigator_Z9 小时前
LeetCode //C - 1201. Ugly Number III
c语言·算法·leetcode