```
class Solution {
public:
int jump(vector<int>& nums) {
int n = nums.size();
if (n <= 1) return 0;
int reach = nums[0], i = 1, count = 0;
while (i < n && reach < n - 1){
count++;
int max = reach;
for (int j = i; j <= reach; j++) {
if (nums[j] + j > max){
max = nums[j] + j;
if(max >= n - 1) return count + 1;
}
}
i = reach + 1;
reach = max;
}
return count + 1;
}
};
```