Jump Game
来源:互联网 发布:自学java不学c语言 编辑:程序博客网 时间:2024/05/17 01:16
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
.
Solution:
2. Formula: dp[i] = Max(dp[i - 1], A[i - 1]) - 1;
public class Solution { public boolean canJump(int[] nums) { if (nums == null || nums.length == 0) return false; int[] dp = new int[nums.length]; dp[0] = 0; for (int i = 1; i < nums.length; i++) { dp[i] = Math.max(dp[i - 1], nums[i - 1]) - 1; if (dp[i] < 0) return false; } return dp[nums.length - 1] >= 0; }}
0 0
- Jump Game
- Jump Game
- Jump Game
- Jump Game
- Jump Game
- Jump Game
- Jump Game
- Jump Game
- Jump Game
- Jump Game
- Jump Game
- Jump Game
- Jump Game
- Jump Game
- Jump Game
- Jump Game
- Jump Game
- Jump Game
- HTTPS 客户端发送请求(二)
- c++中 int类型 与 string类型 的相互转换
- 安装GSD文件
- 利用Java进行MySql数据库的导入和导出
- HTTPS 客户端发送请求(三)
- Jump Game
- 最大值最小化
- ANDROID版本号和版本名称的重要性介绍
- MySQL优化之——查询
- MySQL优化之——插入 更新 删除
- Redis对于key的操作命令
- Android-SharePreference
- JFreeChart简介
- Linux_4.2_多进程程序设计