55. Jumping Game -LeetCode

Experience: This question is pruning and began to think back, but the idea did not expect, and then look at problem solution

Dynamic Programming is really simple, from the look to the future, traversing the penultimate element, if he can reach

Finally, this explanation can reach this point, traversing the third last, if at this point to reach the second, then he will be able to

Reach the last one, shrinking the size of the problem.

 1 class Solution {
 2  public boolean canJump(int[] nums) {
 3           int index=nums.length-1;
 4         for(int i=index-1;i>=0;i--)
 5         {
 6             if(i+nums[i]>=index)
 7             {
 8                 index=i;
 9             }
10         }
11         if(index==0)
12             return true;
13         else 
14             return false;
15         }
16 }

 

Guess you like

Origin www.cnblogs.com/pc-m/p/11070061.html