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;
    }
};
相关推荐
xlq223224 小时前
22.多态(上)
开发语言·c++·算法
D_evil__5 小时前
[C++高频精进] 并发编程:线程基础
c++
云里雾里!5 小时前
力扣 209. 长度最小的子数组:滑动窗口解法完整解析
数据结构·算法·leetcode
Mr_WangAndy6 小时前
C++17 新特性_第二章 C++17 语言特性_std::any和string_view
c++·string_view·c++40周年·c++17新特性·c++新特性any
CoderYanger6 小时前
递归、搜索与回溯-穷举vs暴搜vs深搜vs回溯vs剪枝:12.全排列
java·算法·leetcode·机器学习·深度优先·剪枝·1024程序员节
水天需0107 小时前
C++ 三种指针转换深度解析
c++
言言的底层世界8 小时前
c++中STL容器及算法等
开发语言·c++·经验分享·笔记
Mr_WangAndy8 小时前
C++17 新特性_第一章 C++17 语言特性___has_include,u8字符字面量
c++·c++40周年·c++17新特性·__has_include·u8字面量
liu****8 小时前
八.函数递归
c语言·开发语言·数据结构·c++·算法
Vanranrr9 小时前
C++临时对象与悬空指针:一个导致资源加载失败的隐藏陷阱
服务器·c++·算法