package leetcode;

/**
 * https://leetcode.com/problems/jump-game-ii/
 */
public class Problem45 {
    public int jump(int[] nums) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem45 prob = new Problem45();
        System.out.println(prob.jump(new int[]{2, 3, 1, 1, 4})); // 2
        System.out.println(prob.jump(new int[]{2, 6, 1, 1, 4})); // 2
        System.out.println(prob.jump(new int[]{100, 5, 1, 1, 4})); // 1
        System.out.println(prob.jump(new int[]{5})); // 0
    }
}

@@ -138,15 +138,489 @@
     
-// TODO
+int result = 0;%0A        int i = 0;%0A        while (i %3C nums.length - 1) %7B%0A            int max = 0;%0A            int maxIdx = 0;%0A            for (int j = i + 1; j %3C= i + nums%5Bi%5D && j %3C nums.length; j++) %7B%0A                if (nums%5Bj%5D %3E= max) %7B%0A                    max = nums%5Bj%5D;%0A                    maxIdx = j;%0A                %7D%0A            %7D%0A            result++;%0A            if (i + nums%5Bi%5D %3E= nums.length - 1) %7B%0A                break;%0A            %7D%0A            i = maxIdx;%0A        %7D
 %0A   
@@ -631,17 +631,22 @@
  return 
-0
+result
 ;%0A    %7D%0A
@@ -733,16 +733,18 @@
 em45();%0A
+//
         
@@ -797,32 +797,34 @@
 , 1, 4%7D)); // 2%0A
+//
         System.o
@@ -877,16 +877,168 @@
 ); // 2%0A
+//        System.out.println(prob.jump(new int%5B%5D%7B2, 6, 1, 1, 4%7D)); // 2%0A//        System.out.println(prob.jump(new int%5B%5D%7B2, 2, 3, 1, 2, 4, 1%7D)); // 3%0A//
         
@@ -1101,16 +1101,18 @@
 ); // 1%0A
+//
         
@@ -1161,16 +1161,246 @@
 ); // 0%0A
+//        System.out.println(prob.jump(new int%5B%5D%7B2, 3, 1%7D)); // 1%0A//        System.out.println(prob.jump(new int%5B%5D%7B1, 2, 1, 1, 1%7D)); // 3%0A        System.out.println(prob.jump(new int%5B%5D%7B10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1, 0%7D)); // 2%0A
     %7D%0A%7D%0A

Update problem 45