leetcode: Jump Game II
来源:互联网 发布:linux脚本显示日期格式 编辑:程序博客网 时间:2024/05/29 03:15
最开始先到的是广搜,但是超时......
看了下网上的解答,觉得倒推这种思路不错...基本就是贪心的思想....试想要走到最后一个位置,这一步的起点要离最后一个位置尽可能远...(因为能覆盖到更近的起点的方案肯定也能覆盖到最远的起点)....所以每次不断地向前找最远的起点直到起点....这样时间消耗和空间消耗都极少....妙!!
public class Solution { public int jump(int[] A) { int len = A.length; if(len<=1) { return 0; } int cur=len-1; int count=0; int pre=0; while(true) { if(pre==cur) { return 0; } pre = cur; count++; for(int i=cur-1;i>=0;i--) { if(A[i]+i>=pre) { cur = i; } } if(cur==0) { return count; } } }}
0 0
- 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
- [LeetCode] Jump Game II
- 高质量的PDF转换器
- 用命令和.dSYM 文件查找错误日志
- 分页导航
- 【Leetcode长征系列】Unique Binary Search Trees
- Net4.0的网站在IE10、IE11出现“__doPostBack未定义”的解决办法。
- leetcode: Jump Game II
- 1050. String Subtraction
- Centos6.0使用第三方YUM源(EPEL,RPMForge,RPMFusion)
- Facebook掀企业开源贡献热潮成"开源标兵"
- ViewStub报错:must have a valid layoutResource解决
- Bayer彩色滤波器
- 快速排序法
- 根据浏览器宽度加载图片
- html 缩写与首字母缩写