代码随想录 Leetcode45. 跳跃游戏 II

题目:


代码(首刷看解析 2024年2月15日):

class Solution {
public:
    int jump(vector<int>& nums) {
        if (nums.size() == 1) return 0;
        int res = 0;
        int curDistance = 0;
        int nextDistance = 0;
        for (int i = 0; i < nums.size(); ++i) {
            nextDistance = max(i + nums[i], nextDistance);
            if (i == curDistance) {
                res++;
                curDistance = nextDistance;
                if (nextDistance >= nums.size() - 1) break;
            }
        }
        return res;
    }
};

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-02-16 09:14:01       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-02-16 09:14:01       100 阅读
  3. 在Django里面运行非项目文件

    2024-02-16 09:14:01       82 阅读
  4. Python语言-面向对象

    2024-02-16 09:14:01       91 阅读

热门阅读

  1. AutoSAR(基础入门篇)9.5-实验:配置通信

    2024-02-16 09:14:01       46 阅读
  2. PMP考试之20240216

    2024-02-16 09:14:01       49 阅读
  3. RISC-V和ARM

    2024-02-16 09:14:01       58 阅读
  4. Python数据科学工具大全

    2024-02-16 09:14:01       49 阅读
  5. nodejs和npm和vite

    2024-02-16 09:14:01       50 阅读
  6. C# 随机打乱数组

    2024-02-16 09:14:01       55 阅读
  7. 五个编程原则:Rob Pike‘s 5 Rules of Programming

    2024-02-16 09:14:01       53 阅读
  8. Codeforces Round 925 (Div. 3)

    2024-02-16 09:14:01       61 阅读