leetcode-55. Jump Game
来源:互联网 发布:智能手机自动开机软件 编辑:程序博客网 时间:2024/06/13 22:25
leetcode-55. Jump Game
题目:
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 last index.
For example:
A = [2,3,1,1,4], return true.A = [3,2,1,0,4], return false.
常规贪心算法思路,维护一个到目前为止到达最远的点Farthest,然后遍历Farthest之前的所有点。
public class Solution { public boolean canJump(int[] nums) { int Farthest = 0,pos=0; while(pos<= Farthest){ Farthest = Math.max(nums[pos]+pos,Farthest); if(Farthest>=nums.length-1) return true; pos++; } return false; }}
0 0
- [LeetCode]55.Jump Game
- LeetCode 55.Jump Game
- LeetCode --- 55. Jump Game
- [Leetcode] 55. Jump Game
- [leetcode] 55.Jump Game
- [leetcode] 55.Jump Game
- *LeetCode 55. Jump Game
- LeetCode 55. Jump Game
- [leetcode] 55. Jump Game
- leetcode 55. Jump Game
- 55. Jump Game LeetCode
- 【LeetCode】55. Jump Game
- leetcode 55. Jump Game
- [LeetCode] 55. Jump Game
- LeetCode 55. Jump Game
- LeetCode *** 55. Jump Game
- Leetcode 55. Jump Game
- LeetCode-55.Jump Game
- Linux使用Crontab MySql定时备份
- linux命令大全——文件管理(一)
- 在AndroidStudio中,使用selector完成按钮点击颜色变化功能
- MYSQL学习心得(7) -- 视图
- 关于在新版eclipse中找不到旧版的swing插件的event name面板问题。
- leetcode-55. Jump Game
- android Handler分析
- Struts2的知识整理总结(二)—— Action 应用总结
- mac开发环境配置(1)
- 20、状态模式(State)
- mavenLocal()默认路径
- c++ 模板
- java基础之位运算符
- unity插件Skyshop的介绍与基本操作