国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

[LeetCode] Jump Game II

2019-11-08 02:40:20
字體:
來源:轉載
供稿:網友

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.

Your goal is to reach the last index in the minimum number of jumps.

For example:Given array A = [2,3,1,1,4]

The minimum number of jumps to reach the last index is 2. (Jump 1 step from index 0 to 1, then 3 steps to the last index.)

int jump(int A[], int n){	int pos = 0;	int nextPos = 0;	int count = 0;	while (true)	{		pos = nextPos;		int span = 0;		for (int j = 1; j <= A[pos]; j++)		{			int temp = pos + j;			if (temp+A[temp] > span)			{				nextPos = temp;				span = temp + A[temp];			}		}		count++;		if (nextPos >= n-1)		{			return count;		}	}}


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 栖霞市| 慈利县| 无为县| 竹北市| 灵川县| 陆河县| 登封市| 彩票| 中宁县| 广饶县| 永兴县| 财经| 大宁县| 田东县| SHOW| 郑州市| 中阳县| 乐都县| 无棣县| 涞水县| 石家庄市| 桃江县| 玉田县| 琼中| 永顺县| 太和县| 射洪县| 灵台县| 石狮市| 饶阳县| 新晃| 上林县| 灵台县| 泾阳县| 阿坝县| 徐汇区| 隆昌县| 岢岚县| 防城港市| 祁阳县| 德安县|