首页 > 其他分享 >LeetCode[55]JumpGame

LeetCode[55]JumpGame

时间:2023-08-18 14:36:12浏览次数:49  
标签:index return nums 55 pos false JumpGame true LeetCode

Content

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.

 

Example 1:

Input: nums = [2,3,1,1,4]
Output: true
Explanation: Jump 1 step from index 0 to 1, then 3 steps to the last index.

Example 2:

Input: nums = [3,2,1,0,4]
Output: false
Explanation: You will always arrive at index 3 no matter what. Its maximum jump length is 0, which makes it impossible to reach the last index.

 

Constraints:

  • 1 <= nums.length <= 104
  • 0 <= nums[i] <= 105
Related Topics
  • 贪心
  • 数组
  • 动态规划

  • 标签:index,return,nums,55,pos,false,JumpGame,true,LeetCode
    From: https://www.cnblogs.com/shea24/p/17640409.html
  • 相关文章

    • LeetCode[62]UniquePaths
      ContentThereisarobotonanmxngrid.Therobotisinitiallylocatedatthetop-leftcorner(i.e.,grid[0][0]).Therobottriestomovetothebottom-rightcorner(i.e.,grid[m-1][n-1]).Therobotcanonlymoveeitherdownorrightatanypointi......
    • LeetCode[53]MaximumSubarray
      ContentGivenanintegerarraynums,findthesubarraywiththelargestsum,andreturnitssum. Example1:Input:nums=[-2,1,-3,4,-1,2,1,-5,4]Output:6Explanation:Thesubarray[4,-1,2,1]hasthelargestsum6.Example2:Input:nums=[1]Output:......
    • LeetCode[42]TrappingRainWater
      ContentGivennnon-negativeintegersrepresentinganelevationmapwherethewidthofeachbaris1,computehowmuchwateritcantrapafterraining. Example1:Input:height=[0,1,0,2,1,0,1,3,2,1,2,1]Output:6Explanation:Theaboveelevationmap......
    • LeetCode[32]LongestValidParentheses
      ContentGivenastringcontainingjustthecharacters'('and')',returnthelengthofthelongestvalid(well-formed)parenthesessubstring. Example1:Input:s="(()"Output:2Explanation:Thelongestvalidparentheses......
    • LeetCode[10]RegularExpressionMatching
      ContentGivenaninputstrings andapatternp,implementregularexpressionmatchingwithsupportfor'.'and'*'where:'.'Matchesanysinglecharacter.​​​​'*'Matcheszeroormoreoftheprecedingelement.T......
    • No_55_JumpGame
      ContentYouaregivenanintegerarraynums.Youareinitiallypositionedatthearray'sfirstindex,andeachelementinthearrayrepresentsyourmaximumjumplengthatthatposition.Returntrueifyoucanreachthelastindex,orfalseotherwise.......
    • LeetCode 392.判断子序列
      1.题目:给定字符串 s 和 t ,判断 s 是否为 t 的子序列。字符串的一个子序列是原始字符串删除一些(也可以不删除)字符而不改变剩余字符相对位置形成的新字符串。(例如,"ace"是"abcde"的一个子序列,而"aec"不是)。进阶:如果有大量输入的S,称作S1,S2,...,Sk其中k>=10亿,你需要......
    • #yyds干货盘点# LeetCode程序员面试金典:存在重复元素 II
      题目:给你一个整数数组 nums 和一个整数 k ,判断数组中是否存在两个 不同的索引 i 和 j ,满足 nums[i]==nums[j] 且 abs(i-j)<=k 。如果存在,返回 true ;否则,返回 false 。 示例 1:输入:nums=[1,2,3,1],k=3输出:true示例2:输入:nums=[1,0,1,1],k=1输出......
    • #yyds干货盘点# LeetCode程序员面试金典:组合和四
      1.简述:给你一个由 不同 整数组成的数组 ,和一个目标整数 。请你从 中找出并返回总和为 的元素组合的个数。numstargetnumstarget题目数据保证答案符合32位整数范围。 示例1:输入:nums=[1,2,3],target=4输出:7解释:所有可能的组合为:(1,1,1,1)(1,1,2)(1,2,1)......
    • 【leetcode】1.two sum
      第一题给我干懵了...想达到这个要求把我脑壳都想痛了...Follow-up:CanyoucomeupwithanalgorithmthatislessthanO(n2)timecomplexity?一开始想过用map,但是不能解决重复key的问题。然而我用sort,这个时间复杂度也不好确定。假装我只用了O(n)!(搓手手)(溜走)xxxclassSol......