Similar Idea.

public int jump(int[] nums) { int farIndex = 0, count = 0, best = 0; for (int idx = 0; idx < nums.length && farIndex < nums.length - 1; idx ++) { best = Math.max (best, idx + nums [idx]); if (farIndex == idx) { farIndex = best; count ++; best = 0; } } return count; }Jump Game II