import java.util.*;

public class Solution {
  public int jump(int[] jumps) {
    if (jumps.length == 0) return 0;

    int lastIndex = jumps.length - 1;
    boolean[] visited = new boolean[jumps.length];
    LinkedList<Integer> queue = new LinkedList<Integer>();
    queue.add(0);
    int stepCount = 0;
    visited[0] = true;

    while (!queue.isEmpty()) {
      int queueSize = queue.size();
      for (int i = 0; i < queueSize; i++) {
        int index = queue.removeFirst();
        if (index == lastIndex) {
          return stepCount;
        }

        int maxJump = jumps[index];
        for (int jump = 1; jump <= maxJump; jump++) {
          int newIndex = index + jump;
          if (newIndex >= jumps.length) {
            break;
          }
          if (!visited[newIndex]) {
            visited[newIndex] = true;
            queue.addLast(newIndex);
          }
        }
      }

      stepCount++;
    }

    return stepCount;
  }
}

@@ -107,16 +107,53 @@
 eturn 0;
+%0A    if (jumps.length == 1) return 0;
 %0A%0A    in
@@ -524,12 +524,81 @@
    i
-f (i
+nt maxIndex = Math.min(index + jumps%5Bindex%5D, lastIndex);%0A        if (maxI
 ndex
@@ -636,24 +636,28 @@
 rn stepCount
+ + 1
 ;%0A        %7D%0A
@@ -669,103 +669,37 @@
     
-int maxJump = jumps%5Bindex%5D;%0A        for (int jump = 1; jump %3C= maxJump; jump++) %7B%0A          int
+for (int newIndex = maxIndex;
  new
@@ -708,96 +708,30 @@
 dex 
-=
+%3E
  index
- + jump;%0A          if (newIndex %3E= jumps.length) %7B%0A            break;%0A          %7D
+; newIndex--) %7B
 %0A   
@@ -741,17 +741,16 @@
     if (
-!
 visited%5B
@@ -760,17 +760,23 @@
 Index%5D) 
-%7B
+break;%0A
 %0A       
@@ -778,18 +778,16 @@
         
-  
 visited%5B
@@ -814,18 +814,16 @@
         
-  
 queue.ad
@@ -843,20 +843,8 @@
 x);%0A
-          %7D%0A
     

Optimize jump game ii solution