[刷题]Jump Game
来源:互联网 发布:php 获取session数据 编辑:程序博客网 时间:2024/05/16 11:40
[LintCode]Jump Game
public class Solution { /** * @param A: A list of integers * @return: The boolean answer */ public boolean canJump(int[] A) { // 2015-05-15 if (A == null || A.length == 0) { return false; } int n = A.length; boolean[] can = new boolean[n]; can[0] = true; for (int i = 1; i < n; i++) { can[i] = false; for (int j = 0; j < i; j++) { if (can[j] == true && j + A[j] >= i) { can[i] = true; break; } } } return can[n - 1]; }}
public class Solution { /** * @param A: A list of integers * @return: The boolean answer */ public boolean canJump(int[] A) { // wirte your code here if (A == null || A.length == 0) { return false; } // 默认初始化为false boolean[] can = new boolean[A.length]; can[0] = true; for (int i = 0; i < A.length; i++) { if (!can[i]) { continue; } for (int j = i + 1; j <= i + A[i]; j++) { if (j < A.length) can[j] = true; } } return can[A.length - 1]; }}
0 0
- [刷题]Jump Game
- [刷题]Jump Game II
- 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
- css 特效
- vim中字母大小写变换
- 自定义标签JSTL+国际化
- 嵌套类与局部类
- 毕业设计
- [刷题]Jump Game
- __thread关键字
- DS之求解二叉树的叶子结点和深度
- 二维数组的鞍点问题(c++)
- [刷题]Jump Game II
- C# 截图
- JAVA程序设计基础教程 抽象类、接口与包
- assert()函数用法总结
- Axure RP Pro7.0 之 动态面板初步使用