Jump Game II

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.)

 /*************************************************************************
> File Name: LeetCode045.c
> Author: Juntaran
> Mail: JuntaranMail@gmail.com
> Created Time: Tue 13 May 2016 14:47:33 PM CST
************************************************************************/ /************************************************************************* Jump Game II 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.) ************************************************************************/ #include <stdio.h> int jump(int* nums, int numsSize)
{
if( numsSize <= )
{
return ;
} int left = nums[];
int right = nums[];
int count = ;
int max = ; int i;
for( i=; i<numsSize; i++ )
{
if( i > left )
{
left = right;
count ++;
}
right = (i+nums[i])>right ? (i+nums[i]) : right;
if( left >= numsSize- )
{
return count;
}
}
return ;
} int main()
{
int nums[] = {,,,,};
int numsSize = ; int ret = jump( nums, numsSize );
printf("%d\n", ret); return ;
}

LeetCode 45的更多相关文章

  1. Leetcode 45. Jump Game II(贪心)

    45. Jump Game II 题目链接:https://leetcode.com/problems/jump-game-ii/ Description: Given an array of non ...

  2. [LeetCode] 45. Jump Game II 跳跃游戏之二

    Given an array of non-negative integers, you are initially positioned at the first index of the arra ...

  3. [LeetCode] 45. Jump Game II 解题思路

    Given an array of non-negative integers, you are initially positioned at the first index of the arra ...

  4. [LeetCode] 45. Jump Game II_ Hard tag: Dynamic Programming

    Given an array of non-negative integers, you are initially positioned at the first index of the arra ...

  5. [leetcode]45. Jump Game II青蛙跳(跳到终点最小步数)

    Given an array of non-negative integers, you are initially positioned at the first index of the arra ...

  6. LeetCode 45 Jump Game II(按照数组进行移动)

    题目链接:https://leetcode.com/problems/jump-game-ii/?tab=Description   给定一个数组,数组中的数值表示在当前位置能够向前跳动的最大距离. ...

  7. [LeetCode] 45. Jump Game II 跳跃游戏 II

    Given an array of non-negative integers, you are initially positioned at the first index of the arra ...

  8. LeetCode 45. 跳跃游戏 II | Python

    45. 跳跃游戏 II 题目来源:https://leetcode-cn.com/problems/jump-game-ii 题目 给定一个非负整数数组,你最初位于数组的第一个位置. 数组中的每个元素 ...

  9. Java实现 LeetCode 45 跳跃游戏 II(二)

    45. 跳跃游戏 II 给定一个非负整数数组,你最初位于数组的第一个位置. 数组中的每个元素代表你在该位置可以跳跃的最大长度. 你的目标是使用最少的跳跃次数到达数组的最后一个位置. 示例: 输入: [ ...

  10. 力扣Leetcode 45. 跳跃游戏 II - 贪心思想

    这题是 55.跳跃游戏的升级版 力扣Leetcode 55. 跳跃游戏 给定一个非负整数数组,你最初位于数组的第一个位置. 数组中的每个元素代表你在该位置可以跳跃的最大长度. 你的目标是使用最少的跳跃 ...

随机推荐

  1. string insert 的性能分析

    有这样一个网络传输包. 前端有个固定的包头,包含了后面传输body的长度信息. 在有拷贝的前提下,我们选用什么性能比较高呢?         方案一         复用data_buffer str ...

  2. App Extension编程指南(iOS8/OS X v10.10)中文版

    http://www.cocoachina.com/ios/20141023/10027.html 当iOS 8.0和OS X v10.10发布后,一个全新的概念出现在我们眼前,那就是应用扩展.顾名思 ...

  3. ACM OJ Collection

    浙江大学(ZJU):http://acm.zju.edu.cn/ 北京大学(PKU):http://acm.pku.edu.cn/JudgeOnline/ 同济大学(TJU):http://acm.t ...

  4. Gym 100507I Traffic Jam in Flower Town (模拟)

    Traffic Jam in Flower Town 题目链接: http://acm.hust.edu.cn/vjudge/contest/126546#problem/I Description ...

  5. Spring JdbcTemplate小结

    提供了JdbcTemplate 来封装数据库jdbc操作细节: 包括: 数据库连接[打开/关闭] ,异常转义 ,SQL执行 ,查询结果的转换 使用模板方式封装 jdbc数据库操作-固定流程的动作,提供 ...

  6. ubuntu 如何在recovery模式修改root密码

    今天遇到一个问题, 前提1: ubuntu系统的root密码我一直没有设定  前提2: ubuntu初始创建的sudo用户不知道怎么移除sudo权限用户了. 下面就精彩了, 首先没有root密码,你不 ...

  7. ADO.NET 快速入门(十三):使用 OLE DB 检索数据

    OleDbDataReader 类提供了一种从数据源读取数据记录只进流的方法.如果想使用 SQL Server 7.0 或者更高版本,请参考文章:使用 SQL Server 检索数据.   OleDb ...

  8. 一个简单的小例子让你明白c#中的委托-终于懂了!

    模拟主持人发布一个问题,由多个嘉宾来回答这个问题. 分析:从需求中抽出Host (主持人) 类和Guests (嘉宾) 类. 作为问题的发布者,Host不知道问题如何解答.因此它只能发布这个事件,将事 ...

  9. 使用QQ账号的来发送邮件

    第一步,看图操作如下: 打开QQ邮箱,在设置-帐户,然后再看下图示: 把:POP3/SMTP服务,IMAP/SMTP服务,Exchange服务,CardDAV/CalDAV服务都选择上,保存这样,便可 ...

  10. ListView往TreView里面拖拽

    ListView往TreView里面拖拽       unit Unit1; interface uses   Windows, Messages, SysUtils, Variants, Class ...