My Simple C Solution , O(n) time , O(1) space , 8ms ,only 10 lines!


  • 2
    H
    int jump(int* nums, int numsSize) {
         int now = 0,ret = 0,last = 0;
         for(int i = 0; now < numsSize -1; i++){
             if(nums[i] + i > now)
                  now = nums[i] + i;
             if(i == last)
                 ++ret,last = now;
          }
          return (now > last)? ret + 1 : ret;
     }

  • 1
    F

    Your code is very simple, but could you please add some explanation. The simpler the code is, the harder for people to understand.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.