首页 > 学院 > 开发设计 > 正文

Jump Game

2019-11-08 18:22:21
字体:
来源:转载
供稿:网友

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.

bool fun(int a[], int n){	int step = a[0];	for (int i = 1; i < n; i++)	{		if (step > 0)		{			step--;			step = max(step, a[i]);		}		else		{			return false;		}	}	return true;}


上一篇:第7章 流程控制

下一篇:数独

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表