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;
    }
};
相关推荐
一个不知名程序员www2 小时前
算法学习入门 --- 哈希表和unordered_map、unordered_set(C++)
c++·算法
C++ 老炮儿的技术栈2 小时前
在C++ 程序中调用被 C编译器编译后的函数,为什么要加 extern “C”声明?
c语言·c++·windows·git·vscode·visual studio
%xiao Q2 小时前
GESP C++五级-202406
android·开发语言·c++
Sarvartha3 小时前
C++ STL 栈的便捷使用
c++·算法
夏鹏今天学习了吗3 小时前
【LeetCode热题100(92/100)】多数元素
算法·leetcode·职场和发展
Aevget3 小时前
MFC扩展库BCGControlBar Pro v37.2 - 全新的VS 2026可视化管理器
c++·mfc·bcg·界面控件·ui开发
C+-C资深大佬4 小时前
C++类型判断
开发语言·c++
Yu_Lijing4 小时前
基于C++的《Head First设计模式》笔记——模式合作
c++·笔记·设计模式
zmzb01034 小时前
C++课后习题训练记录Day74
开发语言·c++
cdut_suye5 小时前
解锁函数的魔力:Python 中的多值传递、灵活参数与无名之美
java·数据库·c++·人工智能·python·机器学习·热榜