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 天前
Niagara粒子系统-超炫酷的闪电特效(加餐 纸牌螺旋上升效果)
游戏·游戏引擎
智算菩萨2 天前
儿童游乐空间的双维建构:室内淘气堡与室外亲子乐园的发展学理、功能分野与协同育人机制研究
游戏·游戏策划
marteker2 天前
房地产市场平台Zillow与《魔兽世界》合作展示游戏内房屋
游戏
wanhengidc2 天前
云手机 打造云端算力
运维·服务器·网络·游戏·智能手机
henry1010102 天前
DeepSeek生成的HTML5小游戏 -- 黑8台球
前端·javascript·css·游戏·html
yuanmenghao3 天前
从零开始:使用 Claude Code 打造字母消除游戏
游戏·glm·claudecode
阿甘编程点滴3 天前
2026年推荐以下5款游戏直播提词器
游戏
PieroPc3 天前
HTML5 Canvas 平台跳跃游戏
前端·游戏·html5
Swift社区3 天前
LeetCode 390 消除游戏 - Swift 题解
leetcode·游戏·swift
技术策划Boring3 天前
2025年工作复盘:开放世界3A项目配置管线与性能监控的探索
游戏·ue5·虚幻·p4·perforce