Advertisement
nikunjsoni

45

May 5th, 2021
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.36 KB | None | 0 0
  1. class Solution {
  2. public:
  3.     int jump(vector<int>& nums) {
  4.         int jumps = 0, n = nums.size(), farthest = 0, currEnd = 0;
  5.         for(int i=0; i<n-1; i++){
  6.             farthest = max(farthest, i+nums[i]);
  7.             if(i == currEnd){
  8.                 jumps++;
  9.                 currEnd = farthest;
  10.             }
  11.         }
  12.         return jumps;
  13.     }
  14. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement