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
                
相关推荐
源码老李2 小时前
独立游戏AI音乐指南:用Suno AI让游戏拥有灵魂
人工智能·游戏·ai编程
_守一7 小时前
UE DS+Nakama进行游戏服务器开发(1)源码编译nakama
服务器·游戏
魔士于安8 小时前
Unity 超市总动员 超市收银台 超市货架 超市购物手推车 超市常见商品
游戏·unity·游戏引擎·贴图·模型
zh路西法8 小时前
【Unity实现Oneshot胶卷显形】游戏窗口化与Win32API的使用
游戏·unity·游戏引擎
AIwenIPgeolocation9 小时前
IP地址数据服务:赋能游戏行业体验优化与精细化运营
网络协议·tcp/ip·游戏
前端不太难10 小时前
AISystem:鸿蒙游戏中的 AI 行为驱动
人工智能·游戏·harmonyos
开开心心就好12 小时前
无品牌限制的手机电视投屏工具推荐
科技·游戏·智能手机·edge·电脑·逻辑回归·powerpoint
上海云盾-小余1 天前
BGP 高防与普通高防差异解析:游戏与政企业务该如何选型
游戏
_Evan_Yao1 天前
当 if 成为性能判官:分支预测、流水线冲刷与 Java 中的“猜谜游戏”
人工智能·游戏
魔士于安1 天前
Unity windows 同步 异步 打开文件文件夹工具
游戏·unity·游戏引擎·贴图·模型