leetcode—jump game
1.题目描述
2.解法分析
如果数组中没有零,一定能到达最后一个元素,反之,如果有零,那么如果0前面的元素没有一个能直接跳到0后面的元素的话,肯定是不能到达最后的元素的。
class Solution {public:bool canJump(int A[], int n) {// Start typing your C/C++ solution below// DO NOT write int main() function//如果数组中没有0,肯定能到达int max=0;for(int i=0;i<n-1;++i){if(A[i]==0){if(i>=max)return false;else continue;}if((i+A[i])>max){max=i+A[i];if(max>=n-1)return true;}}return true;}};
leetcode—jump game的更多相关文章
- [LeetCode] Jump Game 跳跃游戏
		Given an array of non-negative integers, you are initially positioned at the first index of the arra ... 
- [LeetCode] Jump Game II 跳跃游戏之二
		Given an array of non-negative integers, you are initially positioned at the first index of the arra ... 
- LeetCode——Jump Game II
		Description: Given an array of non-negative integers, you are initially positioned at the first inde ... 
- [leetcode]Jump Game @ Python
		原题地址:https://oj.leetcode.com/problems/jump-game/ 题意: Given an array of non-negative integers, you ar ... 
- LeetCode: Jump Game II  解题报告
		Jump Game II Given an array of non-negative integers, you are initially positioned at the first inde ... 
- LeetCode: Jump Game Total 解题报告
		Jump GameGiven an array of non-negative integers, you are initially positioned at the first index of ... 
- 动态规划小结 - 一维动态规划 - 时间复杂度 O(n),题 [LeetCode]  Jump Game,Decode Ways
		引言 一维动态规划根据转移方程,复杂度一般有两种情况. func(i) 只和 func(i-1)有关,时间复杂度是O(n),这种情况下空间复杂度往往可以优化为O(1) func(i) 和 func(1 ... 
- [LeetCode] Jump Game II 贪心
		Given an array of non-negative integers, you are initially positioned at the first index of the arra ... 
- Leetcode jump Game II
		Given an array of non-negative integers, you are initially positioned at the first index of the arra ... 
- Leetcode jump Game
		Given an array of non-negative integers, you are initially positioned at the first index of the arra ... 
随机推荐
- VC操作ADO的基本策略
			一.ADO概述 ADO是Microsoft为最新和最强大的数据访问范例 OLE DB 而设计的,是一个便于使用的应用程序层接口.ADO 使您能够编写应用程序以通过 OLE. DB 提供者访问和操作数据 ... 
- rqnoj-106-最大加权矩形-dp
			和我之前做的那个切西瓜的题目相比就是小巫见大巫了.. 运用最长字段和的原理把O(n^4)转化成O(n^3) #include<stdio.h> #include<string.h&g ... 
- 笔记一、Git服务器【转】
			传输协议: 本地传输,SSH协议,Git协议,HTTP协议 git clone /home/git/project.git // 本地clone git ... 
- C#图片切割、图片压缩、缩略图生成
			C#图片切割.图片压缩.缩略图生成的实现代码 /// 图片切割函数 /// </summary> /// <param name="sourceFile"&g ... 
- URAL1748. The Most Complex Number
			1748 反素数 素数的个数随大小的递增而递减 可以相同 注意各种超啊 #include <iostream> #include<cstdio> #include<cst ... 
- Spring安全框架 Spring Security
			Spring Security 的前身是 Acegi Security ,是 Spring 项目组中用来提供安全认证服务的框架. Spring Security 为基于J2EE企业应用软件提供了全面 ... 
- poj 2479 (DP)
			求一个区间内连续两段不相交区间最大和. // File Name: 2479.cpp // Author: Missa_Chen // Created Time: 2013年06月22日 星期六 16 ... 
- 【笨嘴拙舌WINDOWS】键盘消息,鼠标消息
			键盘消息 Windows系统无论何时只有一个窗口(可能是子窗口,也就是控件)能获得焦点. 焦点窗口通过windows消息来响应人的键盘操作,与键盘相关的常用消息罗列如下: WM_KEYDOWN 按 ... 
- 基于jQuery的日历插件
			上个星期看到同事做一个有关日历提醒功能的需求,为了找个插件也是费了不少心思,然后刚好有时间就试着写了一个简单demo 来看下最终效果图吧: 是长得丑了一点,不要吐槽我-.- 首先来说说这个日历主要的制 ... 
- 51nod1364 最大字典序排列
			不断的在cur的后面找最大的符合条件的数扔到cur的前面. 用线段树维护操作就可以了. #include<cstdio> #include<cstring> #include& ... 
