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;
    }
};
相关推荐
恒者走天下29 分钟前
秋招落定,拿到满意的offer,怎么提高自己实际的开发能力,更好的融入团队
c++
做怪小疯子34 分钟前
LeetCode 热题 100——矩阵——旋转图像
算法·leetcode·矩阵
天若有情6731 小时前
【c++】手撸C++ Promise:从零实现通用异步回调组件,支持链式调用+异常安全
开发语言·前端·javascript·c++·promise
学困昇1 小时前
C++中的异常
android·java·c++
sin_hielo1 小时前
leetcode 2435
数据结构·算法·leetcode
合作小小程序员小小店2 小时前
桌面安全开发,桌面二进制%恶意行为拦截查杀%系统安全开发3.0,基于c/c++语言,mfc,win32,ring3,dll,hook,inject,无数据库
c语言·开发语言·c++·安全·系统安全
Codeking__2 小时前
C++ 11 atomic 原子性操作
开发语言·c++
crescent_悦2 小时前
PTA L1-020 帅到没朋友 C++
数据结构·c++·算法
卡提西亚2 小时前
C++笔记-34-map/multimap容器
开发语言·c++·笔记
2***B4493 小时前
C++在金融中的QuantLibXL
开发语言·c++·金融