Leetcode刷题笔记题解(C++):45. 跳跃游戏 II

Leetcode刷题笔记题解(C++):45. 跳跃游戏 II_第1张图片

class Solution {
public:
    int jump(vector& nums) {
        int ans = 0;
        int start = 0;
        int end = 1;
        while(end < nums.size()){
            int maxpos = 0;
            for(int i = start;i= nums.size()) return ans+1;
            }
            start = end;
            end = maxpos+1;
            ans++;
        }
        return ans;
    }
};

你可能感兴趣的:(Leetcode算法题解,leetcode,笔记,c++)