LeetCode 44 Jump Game II
来源:互联网 发布:指纹打卡机导出数据 编辑:程序博客网 时间:2024/04/27 15:08
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.)
思路:使用递归,始终去寻找最小的i能到目标位置。
class Counter {public static int counter;}public class Solution {public int jump(int[] A) {Counter.counter = 0;return jump(A, A.length - 1);}private int jump(int[] A, int end) {int i = 0;for (; i < end; i++) {if (i + A[i] >= end) {Counter.counter++;break;}}if (i == 0)return Counter.counter;jump(A, i);return Counter.counter;}}
0 0
- LeetCode 44 Jump Game II
- LeetCode: Jump Game II
- LeetCode Jump Game II
- LeetCode: Jump Game II
- [Leetcode] Jump Game II
- [LeetCode] Jump Game II
- [Leetcode] Jump Game ii
- leetcode Jump Game II
- leetcode Jump Game II
- [LeetCode]Jump Game II
- [leetcode]Jump Game II
- LeetCode-Jump Game II
- [leetcode] Jump Game II
- LeetCode - Jump Game II
- LeetCode:Jump Game II
- LeetCode | Jump Game II
- 【Leetcode】Jump Game II
- LeetCode Jump Game II
- 2亿QQ在线背后的web敏捷开发模式
- 数据库之存储过程创建表以及for循环插入数据
- HttpClient入门
- DSP/BIOS使用之初窥门径——滴答时钟及烧写Flash
- Oracle 中的一些重要V$ 动态性能视图,系统视图和表
- LeetCode 44 Jump Game II
- 阅读的时候你注意过这些吗?
- mutex死锁追踪
- 由一个例子想到对事务脚本模式的问题
- root
- PCB设计资料:看到最后才知道是福利
- 关于performSelector
- android 圆形进度条 自定义view
- 运维工程师必备之MySQL数据的主从复制、半同步复制和主主复制详解