JasonChang

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
 1 public class Solution {
 2     public int jump(int[] A) {
 3         if(A == null){
 4             return 0;
 5         }
 6         int len = A.length;
 7         if(len == 0 || len == 1){
 8             return 0;
 9         }
10         
11         int cur = 0;
12         int next = 0;
13         int ret = 0;
14         
15         for(int i = 0; i < len; i++){
16             if(i > cur){
17                 cur = next;
18                 ret++;
19             }
20             next = Math.max(next, i + A[i]);
21         }
22         return ret;
23     }
24 }

 

posted on 2013-11-19 16:07  JasonChang  阅读(134)  评论(0编辑  收藏  举报