class Solution {
public:
int jump(vector<int>& nums) {
int ans = 0;
int start = 0, end = 1;
while(end < nums.size()){
int maxpos = 0;
for(int i = start; i < end; i++){
maxpos = max(maxpos, i + nums[i]);
}
start = end;
end = maxpos + 1;
ans++;
}
return ans;
}
};
Leecode45 跳跃游戏2
最新推荐文章于 2024-07-25 16:06:51 发布