2026.02.05 (贪心)买卖股票2 & 跳跃游戏 1 & 2

37. 解数独

python 复制代码
class Solution:
    def maxProfit(self, prices: List[int]) -> int:
        profix = 0
        for i in range(1, len(prices)):
            diff = prices[i] - prices[i - 1]
            if diff > 0:
                profix += diff
        return profix

python 复制代码
class Solution:
    def canJump(self, nums: List[int]) -> bool:
        farthest = 0
        n = len(nums)

        for i in range(n):
            if i > farthest:
                return False
            
            farthest = max(farthest, i + nums[i])

            if farthest >= n - 1:
                return True
        return False

45. 跳跃游戏 II

python 复制代码
class Solution:
    def jump(self, nums: List[int]) -> int:
        step = 0
        n = len(nums)
        if n == 1:
            return 0
        end = 0
        farthest = 0

        for i in range(n):
            farthest = max(farthest, i + nums[i])

            if i == end:
                # 跳到最远的距离,此时需要再跳一次
                step += 1
                end = farthest
                if end >= n - 1:
                    break
        
        return step
                
相关推荐
快乐星空Maker11 小时前
C++【生存游戏】开发:荒岛往事 第二期
游戏
LJHclasstore_luo13 小时前
【GoC游戏】等(wait)1.0.0版本
游戏·goc编程
码来的小朋友16 小时前
国风乡村 3D 地图生成器世界
游戏
河南花仙子科技1 天前
小游戏开发中常见的BUG类型及成因
人工智能·科技·游戏·bug
爱自由的代码工1 天前
游戏上线前需要准备什么:核心逻辑、执行步骤与关键指标
游戏·游戏发行·游戏运营·游戏分发
liulilittle1 天前
麻将系统架构
服务器·网络·分布式·游戏·系统架构·通信
熬夜苦读学习2 天前
基于websocket的多用户五子棋网页游戏
linux·服务器·网络·websocket·网络协议·游戏·五子棋
yangmu32032 天前
【碧蓝幻想Relink】DPS伤害统计Mod安装教程 + XMOD物品面板功能推荐
游戏
lxysbly2 天前
Android PS3模拟器下载推荐2026|安卓PS3模拟器哪个好?手机玩PS3游戏指南
android·游戏·智能手机
笨鸟先飞的橘猫3 天前
游戏场景之大世界架构设计构想
游戏