> For the complete documentation index, see [llms.txt](https://ucan.gitbook.io/notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ucan.gitbook.io/notes/untitled.md).

# 45. Jump Game II

{% hint style="info" %}
BFS & Greedy
{% endhint %}

```java
class Solution {
    public int jump(int[] nums) {
        // result
        int count = 0;
        // the last index of next layer;
        int nextEnd = 0;
        // the last index of current layer;
        int currentEnd = 0;
        for(int i =0; i<nums.length-1; i++){
            nextEnd = i+nums[i]>nextEnd? i+nums[i]: nextEnd;
            if (i==currentEnd){
                count++;
                currentEnd = nextEnd;
            }
        }
        return count;
    }
}
```
