1 class Solution {
 2 public:
 3     int jump(int A[], int n) {
 4         
 5         if (n <= 1) return 0;
 6         
 7         int maxReachedLastTime = 0;
 8         int maxReachedNow = 0;
 9         int minSteps = 0;
10         
11         for (int index = 0; index<n; index++){
12             
13             if (index > maxReachedLastTime){
14                 
15                 maxReachedLastTime = maxReachedNow;
16                 minSteps++;
17             } 
18             
19             if (index+A[index]>maxReachedNow) maxReachedNow = index+A[index];
20         }
21         
22         return minSteps;
23     }
24 };

 

posted on 2013-05-13 02:53  tanghulu321  阅读(163)  评论(0编辑  收藏  举报