45、跳跃游戏
class Solution
{
public:
int jump(vector<int>& nums)
{
int temp = nums[0];
int start = 0;
int end = 0;
int count = 0;
int len = nums.size() - 1;
while (temp < len)
{
for (int i = start; i <= end; i++)
{
int temp1 = nums[i] + i;
temp = (temp >temp1 ? temp : temp1);
}
start = end + 1;
end = temp;
count++;
}
return count;
}
};
原文:https://www.cnblogs.com/wfplingyun/p/12828677.html