*Jump Game

Given an array of non-negative integers, you are initially positioned at the first index of the array.

Each element in the array represents your maximum jump length at that position.

Determine if you are able to reach the last index.

For example:
A = [2,3,1,1,4], return true.

A = [3,2,1,0,4], return false.

 

 

思路: 九章算法DP题解固定思路

 

 

 1     public boolean canJump(int[] nums) 
 2     {
 3         boolean[] can = new boolean[nums.length];
 4         can[0]=true;
 5         
 6         for(int i=1;i<nums.length;i++)
 7            for(int j=i-1;j>=0;j--)
 8            {
 9                if(can[j]&&nums[j]+j>=i)
10                {
11                    can[i]=true;
12                    break;
13                }
14            }
15            
16            
17         return can[nums.length-1];
18         
19 
20     }
21     

reference: http://www.jiuzhang.com/solutions/jump-game/

posted @ 2015-09-23 06:20  Hygeia  阅读(170)  评论(0编辑  收藏  举报