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
                
相关推荐
凯基迪科技8 小时前
Unity游戏加密锁逆向方案、选型与攻防分析
游戏·unity·游戏引擎
Solange__8 小时前
航天科普怎么用AI生成3D场景?从科学约束、尺度分层到网页展示的完整方案
图像处理·人工智能·游戏·3d·ai·自然语言处理·关卡设计
C MIKE15 小时前
小熊杂货铺小游戏开发
游戏
装备研究社1 天前
对峙2掉线排查实测
游戏
xcLeigh1 天前
Unity基础:Destroy与DestroyImmediate——正确销毁游戏物体的方式
游戏·unity·游戏引擎·教程
sunxfancy1 天前
EVEngine 0.6 到 0.6.1:让 AI 参与游戏开发,还需要补上哪些环节?
游戏
sunxfancy1 天前
AI 改完场景,怎么知道没改坏?EVEngine 0.6.1 的白盒自动试玩
游戏
风无雨1 天前
三角洲如何快速拾取物品
游戏
老王的笔记v2 天前
71期 免费开源游戏资源管理工具 Pavise模式切换 游戏库 程序白名单与系统体检
游戏·电脑
Escalating_xu2 天前
【C语言项目实战】贪吃蛇(下):移动、碰撞与计分,完成一局可玩的游戏
c语言·开发语言·游戏