题目链接 题目大意:与55题类似,只是这里要求出跳数. 法一(借鉴):贪心.cur表示当前能到达的最远距离,pre表示上一次能到达的最远距离,每到一个位置更新一次最远距离cur,如果当前位置超过了上一次能到达的最远距离,则更新跳数和上一次能到达的最远距离.代码如下(耗时6ms): public int jump(int[] nums) { int cur = 0, res = 0, pre = 0; for(int i = 0; i < nums.length; i++) { //如果当前位置超…
45. Jump Game II 题目链接:https://leetcode.com/problems/jump-game-ii/ Description: 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 tha…
55. Jump Game 第一种方法: 只要找到一个方式可以到达,那当前位置就是可以到达的,所以可以break class Solution { public: bool canJump(vector<int>& nums) { int length = nums.size(); ) return false; vector<bool> dp(length,false); dp[] = true; ;i < length;i++){ ;j >= ;j--){…
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 45: Jump Game IIhttps://oj.leetcode.com/problems/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 arra…
55. Jump Game Description 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 la…
闲来无事,突然看到博客园首页上有人写了篇了华为2018软件岗笔试题解题思路和源代码分享.看了下题目,感觉第一题能做出来,就想着用刚刚学的python试着写一下,花费的时间有点长~~,看来又好长时间没练习算法了. 题目描述 输入两个字母串,将两个字母串都包含的字母用'_'替换后,输出两个字母串的剩余部分. 输入描述: 输入两个字符串,字符串最大长度为100.字符串只包含字母,不可能为空串,区分大小写. 输出描述: 按字符串顺序输出处理后的字符串 示例1 输入 abcd bdef 输出 a_c_ _…
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 nu…
Jump Game Problem statement: 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…
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 nu…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 贪心 日期 题目地址:https://leetcode.com/problems/reach-a-number/description/ 题目描述 Given an array of non-negative integers, you are initially positioned at the first index of the array.…