class Solution {
public:
int jump(vector<int>& nums) {
int ans = 0;
int start = 0;
int end = 1;
while(end < nums.size()){
int maxpos = 0;
for(int i = start;i<end;i++){
maxpos = max(maxpos,nums[i]+i);
if(maxpos >= nums.size()) return ans+1;
}
start = end;
end = maxpos+1;
ans++;
}
return ans;
}
};
Leetcode刷题笔记题解(C++):45. 跳跃游戏 II
最新推荐文章于 2024-02-18 22:24:05 发布