LeetCode 55
Jump Game
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.
/*************************************************************************
> File Name: LeetCode055.c
> Author: Juntaran
> Mail: JuntaranMail@gmail.com
> Created Time: Wed 11 May 2016 20:30:25 PM CST
************************************************************************/ /************************************************************************* Jump Game 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 <stdio.h> #define MAX(a,b) ((a)>(b) ? (a) : (b)) int canJump(int* nums, int numsSize) { int sum = ; int i;
for( i=; i<numsSize && sum<=numsSize; i++ )
{
if (i > sum)
{
return ;
}
sum = MAX( nums[i]+i, sum );
printf("sum is %d\n", sum);
}
return ;
} int main()
{
int nums[] = { ,,,, };
int numsSize = ; int ret = canJump( nums, numsSize );
printf("%d\n", ret); return ;
}
LeetCode 55的更多相关文章
- [LeetCode] 55. Jump Game 跳跃游戏
Given an array of non-negative integers, you are initially positioned at the first index of the arra ...
- Jump Game 的三种思路 - leetcode 55. Jump Game
Jump Game 是一道有意思的题目.题意很简单,给你一个数组,数组的每个元素表示你能前进的最大步数,最开始时你在第一个元素所在的位置,之后你可以前进,问能不能到达最后一个元素位置. 比如: A = ...
- LeetCode 55. Jump Game (跳跃游戏)
Given an array of non-negative integers, you are initially positioned at the first index of the arra ...
- [LeetCode] 55. Jump Game_ Medium tag: Dynamic Programming
Given an array of non-negative integers, you are initially positioned at the first index of the arra ...
- LeetCode: 55. Jump Game(Medium)
1. 原题链接 https://leetcode.com/problems/jump-game/description/ 2. 题目要求 给定一个整型数组,数组中没有负数.从第一个元素开始,每个元素的 ...
- Leetcode 55. Jump Game & 45. Jump Game II
55. Jump Game Description Given an array of non-negative integers, you are initially positioned at t ...
- leetcode 55. Jump Game、45. Jump Game II(贪心)
55. Jump Game 第一种方法: 只要找到一个方式可以到达,那当前位置就是可以到达的,所以可以break class Solution { public: bool canJump(vecto ...
- Java实现 LeetCode 55 跳跃游戏
55. 跳跃游戏 给定一个非负整数数组,你最初位于数组的第一个位置. 数组中的每个元素代表你在该位置可以跳跃的最大长度. 判断你是否能够到达最后一个位置. 示例 1: 输入: [2,3,1,1,4] ...
- [LeetCode]55. 跳跃游戏(贪心)
题目 给定一个非负整数数组,你最初位于数组的第一个位置. 数组中的每个元素代表你在该位置可以跳跃的最大长度. 判断你是否能够到达最后一个位置. 示例 1: 输入: [2,3,1,1,4] 输出: tr ...
- leetcode 55. 跳跃游戏 及 45. 跳跃游戏 II
55. 跳跃游戏 问题描述 给定一个非负整数数组,你最初位于数组的第一个位置. 数组中的每个元素代表你在该位置可以跳跃的最大长度. 判断你是否能够到达最后一个位置. 示例 1: 输入: [2,3,1, ...
随机推荐
- Jmeter_初步认识随笔
1. 简介 Apache JMeter是100%纯java桌面应用程序,被设计用来测试客户端/服务器结构的软件(例如web应用程序).它可以用来测试包括基于静态和动态资源程序的性能,例如静态文件,Ja ...
- android ListView进阶
ListView 1.在android 开发中很多时候都要用到ListView的这个控件的,但用这个控件的时候会遇到一些问题,如在ListView中有Button按钮,就需要将按钮的监听事件给分离出来 ...
- 国内外从事CV相关的企业[转]
提示:本文为笔者原创,转载请注明出处:blog.csdn.net/carson2005 经常碰到朋友问我国内从事计算机视觉(CV)领域的公司的发展情况,产品情况,甚至找工作等问题,这里,我给出自己收集 ...
- SQL Server 2008 无法保存表的更改
MS SQL Server 2008 在建完表后,如果要重新设计表,如修改字段长度,就会提示:“当用户在在SQL Server 2008企业管理器中更改表结构时,必须要先删除原来的表,然后重新创建新表 ...
- 如何在DigitalOcean安装Ghost
查看原文: http://leancodingnow.com/how-to-install-ghost-on-digital-ocean-vps/ 这篇文章主要讲一下如何在DigitalOcean V ...
- Perl 引用与匿名数组
写这篇是因为工作遇到一个需要使用列表作为hash的值的问题,这在Python中是非常简单而轻松的事,如下面这段python程序. def add_to_index(index, keyword, ur ...
- P、NP、NP-Complete、NP-hard问题
Table of Contents 1 遇到难题怎么办? 2 什么是P.NP.NP-Complete和NP-hard 3 P = NP ???? 4 参考 1 遇到难题怎么办? 遇到一个问题,通常我们 ...
- 30款css3实现的鼠标经过图片显示描述特效
今天给大家分享30款css3实现的鼠标经过图片显示描述特效,鼠标经过这些图片的时候以非常炫的方式显示图片的描述.为保证最佳的效果,请在 IE10+.Chrome.Firefox 和 Safari 等现 ...
- org.apache.hadoop.conf-Configurable
从包名可以看出这个包里面都是配置相关的类:从类名上可以看出这是一个接口,或者说配置类接口.内容很少. package org.apache.hadoop.conf; /** Something tha ...
- JS Math算数
Math.ceil()ceil() 方法可对一个数进行上舍入. ceil英译 天花板 参数必须是一个数值.返回值大于等于 x,并且与它最接近的整数. Math.floor()floor() 方法可对一 ...