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
                
相关推荐
乌萨达12 小时前
低配电脑玩手游怎么设置?4GB、8GB内存与模拟器选择指南
游戏·电脑·安卓模拟器·雷电模拟器
林川~012 天前
Unity 万能物理检测工具:射线检测 / 范围检测 / 层级过滤 / 编辑器可视化(可直接拿去用)
游戏·unity·c#·射线检测·通用工具
一孤程3 天前
游戏测试专题第七篇:游戏自动化测试实战
游戏·测试
一孤程3 天前
游戏测试专题第八篇:游戏安全测试与反外挂
游戏·测试
河南花仙子科技4 天前
小游戏社交裂变功能的高阶设计思路
大数据·科技·游戏
一孤程4 天前
游戏测试专题第五篇:游戏兼容性测试与多端适配
游戏·测试
狂人开飞机5 天前
23、实战平台跳跃游戏
游戏·游戏引擎·godot
甲维斯5 天前
0代码,0建模,3句话开发一个3D游戏!
前端·游戏·游戏开发
笨鸟先飞的橘猫5 天前
树结构在游戏行业中的应用
学习·游戏
Sylvia33.5 天前
火星数据体育API|一站式接入足球篮球电竞等18+项目实时数据
java·开发语言·python·websocket·游戏