首页 > 其他 > 详细

LeetCode – Refresh – Jump Game II

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

Same with Jump Game I. Just need a step parameter and assume there is no "0" value in the array.

 1 class Solution {
 2 public:
 3     int jump(int A[], int n) {
 4         if (n < 2) return 0;
 5         int current = 0, i = 0, steps = 0;
 6         while (i < n) {
 7             current = i + A[i];
 8             steps++;
 9             if (current >= n-1) return steps;
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 II

原文:http://www.cnblogs.com/shuashuashua/p/4352638.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!