码迷,mamicode.com
首页 > 其他好文 > 详细

LeetCode – Refresh – Jump Game

时间:2015-03-20 06:51:03      阅读:127      评论:0      收藏:0      [点我收藏+]

标签:

Need a corner case check for only one element [0].

 1 class Solution {
 2 public:
 3     bool canJump(int A[], int n) {
 4         if (n < 2) return true;
 5         int i = 0, current = 0;
 6         while (i < n) {
 7             if (A[i] == 0) return false;
 8             current = i + A[i];
 9             if (current >= n-1) return true;
10             for (int j = i+1, tmp = 0; j <= current; j++) {
11                 if (j + A[j] > tmp) {
12                     tmp = j + A[j];
13                     i = j;
14                 }
15             }
16         }
17     }
18 };

 

LeetCode – Refresh – Jump Game

标签:

原文地址:http://www.cnblogs.com/shuashuashua/p/4352637.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!