leetcode 5.4

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;
}
};

posted @ 2020-05-04 22:50  凌丨云  阅读(98)  评论(0)    收藏  举报