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
                
相关推荐
达子6662 小时前
第30章_综合案例:HarmonyOs开发图解之 俄罗斯方块游戏
游戏·华为·harmonyos
nujnewnehc9 小时前
游戏辅助后续之yolo
游戏·游戏开发
魔术师Dix1 天前
一个轮子:Luban Skill 制作演示
游戏·unity·ai编程
极客侃科技1 天前
游戏本办公两用笔记本推荐,来酷斗战者 战7000P 酷睿版兼顾两种需求
游戏
ownkss1 天前
游戏买量素材测试方法:核心逻辑、执行步骤与关键指标
游戏
山东布谷网络科技2 天前
靠“社交+游戏”突围:中东语聊APP前景预测与低成本运营案例
人工智能·游戏
郝学胜-神的一滴2 天前
[简化版 GAMES 104] 现代游戏引擎 04:从0到1构建你的游戏世界
c++·游戏·unity·游戏引擎·软件工程·unreal engine
灼灼其华tzl2 天前
飞机大战游戏1
游戏
爱勇宝2 天前
《完蛋!我被男同学包围了》为什么会火?不只是因为“高中生玩票”
游戏·游戏开发
中国搜索直付通2 天前
游戏车机端支付通道,会是下一个被低估的合规战场吗?
java·大数据·开发语言·人工智能·游戏