122. 买卖股票的最佳时机 II
func maxProfit(prices []int) int {
maxP := 0
for i := 1; i < len(prices); i++ {
p := prices[i]-prices[i-1]
if p > 0 {
maxP += p
}
}
return maxP
}
55. 跳跃游戏
func canJump(nums []int) bool {
length := len(nums)
if length == 1 {
return true
}
cover := 0
for i := 0; i <= cover; i++ {
cover = max(i+nums[i], cover)
if cover >= length-1 {
return true
}
}
return false
}
45.跳跃游戏 II
扫描二维码,在手机上阅读
推荐阅读:
收藏