Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- int jump(vector<int>& nums) {
- int jumps = 0, n = nums.size(), farthest = 0, currEnd = 0;
- for(int i=0; i<n-1; i++){
- farthest = max(farthest, i+nums[i]);
- if(i == currEnd){
- jumps++;
- currEnd = farthest;
- }
- }
- return jumps;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement