<span style="font-size:18px;">/*************************************************************************
> File Name: Jump.cpp
> Author:
> Mail:
> Created Time: 2014年08月25日 星期一 15时20分37秒
>Description:
Given an array of non-negative integers, you are initially positioned at the first index of the array.
Each element in the array represents your maximum jump length at that position.
Determine if you are able to reach the last index.
For example:
A = [2,3,1,1,4], return true.
A = [3,2,1,0,4], return false.
************************************************************************/
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
using namespace std;
bool solution(int *map ,int len)
{
int cur = len;
int i;
for(i = len -1; i >=0; i--)
{
if(i +map[i] >= cur)
{
cur = i;
}
}
if(cur == 0)
{
return true;
}
else
{
return false;
}
}
int main()
{
int a[] = {3,2,1,0.4};
if(solution(a,5))
{
printf("OK");
}
else
{
printf("false");
}
}</span>
Jump
最新推荐文章于 2025-06-05 16:51:58 发布