国产探花免费观看_亚洲丰满少妇自慰呻吟_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;		}	}}


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 两当县| 温宿县| 平泉县| 绍兴县| 绍兴县| 武宁县| 九龙城区| 安仁县| 沐川县| 平塘县| 兴城市| 潢川县| 页游| 柳江县| 马鞍山市| 施秉县| 塔城市| 乌兰浩特市| 苍梧县| 合江县| 南郑县| 柘城县| 祁门县| 沂源县| 荥经县| 登封市| 宁夏| 靖边县| 慈利县| 库伦旗| 高要市| 新闻| 玉门市| 名山县| 沿河| 南陵县| 教育| 永福县| 晋江市| 光山县| 志丹县|