C++ | Leetcode C++题解之第45题跳跃游戏II

题目:

题解:

cpp 复制代码
class Solution {
public:
    int jump(vector<int>& nums) {
        int maxPos = 0, n = nums.size(), end = 0, step = 0;
        for (int i = 0; i < n - 1; ++i) {
            if (maxPos >= i) {
                maxPos = max(maxPos, i + nums[i]);
                if (i == end) {
                    end = maxPos;
                    ++step;
                }
            }
        }
        return step;
    }
};
相关推荐
小白程序员成长日记2 小时前
2025.11.24 力扣每日一题
算法·leetcode·职场和发展
有一个好名字2 小时前
LeetCode跳跃游戏:思路与题解全解析
算法·leetcode·游戏
爱学习的小邓同学2 小时前
C++ --- 多态
开发语言·c++
2501_941870563 小时前
Python在高并发微服务数据同步与分布式事务处理中的实践与优化
leetcode
2501_941147715 小时前
高并发微服务架构Spring Cloud与Dubbo在互联网优化实践经验分享
leetcode
Swift社区7 小时前
LeetCode 432 - 全 O(1) 的数据结构
数据结构·算法·leetcode
资深web全栈开发8 小时前
LeetCode 1015. 可被 K 整除的最小整数 - 数学推导与鸽巢原理
算法·leetcode·职场和发展
leoufung8 小时前
链表题目讲解 —— 删除链表的倒数第 n 个节点(LeetCode 19)
数据结构·leetcode·链表
CoderYanger9 小时前
优选算法-队列+宽搜(BFS):72.二叉树的最大宽度
java·开发语言·算法·leetcode·职场和发展·宽度优先·1024程序员节