[leetcode]45. Jump Game II 跳棋游戏2 C++/PYTHON实现【hard难度】

该博客探讨了LeetCode中的45号问题——'Jump Game II',这是一个关于如何在给定非负整数数组中以最少跳跃次数到达最后一个元素的难题。博主提供了C++和Python两种实现方式,并详细解释了贪心算法的思路。通过示例数组[2,3,1,1,4],说明了如何在最小步骤数(2步)内完成跳跃。" 50395720,5569311,Hadoop集群中datanode停止问题解析,"['Hadoop', '大数据开发', '集群管理']
摘要由CSDN通过智能技术生成

题目

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 number of jumps.
For example:
Given array A = [2,3,1,1,4]
The minimum number of jumps to reach the last index is 2. (Jump 1 step from index 0 to 1, then 3 steps to the last index.)

翻译一下 是jump gamehttp://blog.csdn.net/zl87758539/article/details/51694895那个题目派生出来的。
之前那个是问你能不能跳到最后一个,现在是给你一个数组,肯定能跳到最后,问你最少需要多少步。

其实思路差不多的,之前用贪心,比如说n个数,第i个数跳的最远记下来, G=max(G,nums[i]+i)
现在肯定也要记,只不过是,记每一步跳的最远,我们设一个 Gstep 也可以简称 G

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值