【leetocode】55. Jump Game
You are given an integer array nums. You are initially positioned at the array's first index, and each element in the array represents your maximum jump length at that position. Return true if you can reach the last index, or false otherwise.
class Solution {
public:
bool canJump(vector<int>& nums) {
int n=nums.size();
int i=0,step=nums[i];
while(i<=step){
step=max(step,i+nums[i]);
if(step>=n-1) break;
i++;
}
return step>=n-1;
}
};
【leetocode】55. Jump Game的更多相关文章
- 【LeetCode】55. Jump Game
Jump Game Given an array of non-negative integers, you are initially positioned at the first index o ...
- 【LeetCode】55. Jump Game 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 贪心 日期 题目地址:https://leetcod ...
- 【概率论】5-5:负二项分布(The Negative Binomial Distribution)
title: [概率论]5-5:负二项分布(The Negative Binomial Distribution) categories: - Mathematic - Probability key ...
- 【一天一道LeetCode】#55. Jump Game
一天一道LeetCode系列 (一)题目 Given an array of non-negative integers, you are initially positioned at the fi ...
- 【Leetcode】1340. Jump Game V 【动态规划/记忆性搜索】
Given an array of integers arr and an integer d. In one step you can jump from index i to index: i + ...
- 【LeetCode】45. Jump Game II 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 贪心 日期 题目地址:https://leetcod ...
- 【原创】leetCodeOj --- Jump Game II 解题报告
原题地址: https://oj.leetcode.com/problems/jump-game-ii/ 题目内容: Given an array of non-negative integers, ...
- 【LeetCode】45. Jump Game II
Jump Game II Given an array of non-negative integers, you are initially positioned at the first inde ...
- 【LEETCODE】55、数组分类,适中级别,题目:79、611、950
第950题,这题我是真的没想到居然会说使用队列去做,大神的答案,拿过来瞻仰一下 package y2019.Algorithm.array; import java.util.HashMap; imp ...
随机推荐
- hdu 5084 HeHe (观察思考题)
题意: 给一个n行n列的矩阵M.这个矩阵M由2n-1数构成.分别是t1,t2,....t(2n-1). m个query.每个query形式:ri, ci. 第i个query的答案 ans[i]=E[( ...
- vim 打开文件的常用操作
一.如果在终端中开没有打开vim,可以: 横向分割显示: $ vim -o filename1 filename2 纵向分割显示: $ vim -O filename1 filename2 二.如果已 ...
- Ubuntu安装数据库
1.通过命令行安装:sudo apt-get install mysql-client mysql-server 2.安装过程中输入数据库密码("123456",root) 3.使 ...
- Connected to an idle instance.
Connected to an idle instance:连接到空闲实例 原因:数据库或者监听没启动
- Go语言实现APPID登录
package thirdparty import ( "crypto/rsa" "fmt" "github.com/dgrijalva/jwt-go ...
- 【java+selenium3】模拟键盘操作 (十二)
一.键盘操作 用代码来模拟键盘的Enter或一系列的组合键,前面使用sendkeys()方法模拟键盘的输入,除此之外还可以模拟键盘组合键输入如下: 整理一些比较常用的键盘操作如下: sendKeys( ...
- 六问六答理解ForkJoin原理
摘要:ForkJoin线程池是将任务分割为子任务,有可能子任务还是很大,还需要进一步拆解,最终得到足够小的任务. 本文分享自华为云社区<ForkJoin线程池的学习和思考>,作者:brea ...
- LeetCode 199. 二叉树的右视图 C++ 用时超100%
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode ...
- C# 两个具有相同属性的类赋值
最近有遇到两个类之间的赋值问题,两个类的属性几乎都一样的,所以写了个通过反射获取属性的然后赋值的方法,把一个类的属性的值赋值给另一个类. 框架是.net 4.5 public static D Map ...
- 问题 K: A/B Problem
题目描述 做了A+B Problem,A/B Problem不是什么问题了吧! 输入 每组测试样例一行,首先一个号码A,中间一个或多个空格,然后一个符号( / 或者 % ),然后又是空格,后面又是一个 ...