LeetCode-jump-game-ii

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.

Your goal is to reach the last index in the minimum number of jumps.

For example:
Given array A =[2,3,1,1,4]

The minimum number of jumps to reach the last index is2. (Jump1step from index 0 to 1, then3steps to the last index.)

public class Solution {
   public static int jump(int[] A) {
        if(A.length==0||A.length==1)
            return 0;
        int len = A.length;
        int index=0;
        int count=0;
        while (index < len-1){
            if(A[index]+index>=len-1){
                count++;
                break;
            }
            int tmp = decide(A,index);
            index+=tmp;
            count++;
        }
        return count;
    }
 
    private static int decide(int[] a,int index) {
        int max=Integer.MIN_VALUE;
        int tag=0;
        for (int i = 1; i 

 

你可能感兴趣的:(LeetCode)