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
                
相关推荐
金銀銅鐵14 小时前
借助 Pygame 探索最大公约数的规律
python·数学·游戏
nujnewnehc5 天前
不会 py, 用 ai 写了个游戏辅助的感受
人工智能·游戏
jump_jump6 天前
为了重玩金庸群侠传,我研究了一下 Ruffle 怎么复活 Flash
游戏·rust·github
XIAOHEZIcode7 天前
Linux系统鼠标偏移常见原因以及修复方案
linux·运维·游戏
Aloys_Code7 天前
逆向一个被遗忘的DVD游戏格式:从DES加密到Rust模拟器
游戏·模拟器·retroarch·复古游戏·native32·sunplus·赤刃·钢铁风暴
金銀銅鐵8 天前
用 Python 实现 Take-Away 游戏
python·游戏
金銀銅鐵8 天前
用 Pygame 实现 15 puzzle
python·数学·游戏
两水先木示10 天前
【Unity3D】小游戏启动优化、发热优化、蒙皮网格优化
游戏
资源分享助手10 天前
杀戮尖塔2下载、Slay the Spire 2中文版、卡牌肉鸽游戏、杀戮尖塔2联机、杀戮尖塔2攻略
游戏
Swift社区11 天前
当 AI 接管游戏世界:鸿蒙游戏 Workspace Runtime 架构揭秘
人工智能·游戏·harmonyos