Another java one pass but iterating nums backwards


  • 0
    C
    public class Solution {
        public boolean canJump(int[] nums) {
            int n = nums.length;
            int sofar = n-1;
            for (int i = n-2; i >= 0; --i) {
                if (i + nums[i] >= sofar) {
                    sofar = i;
                }
            }
            return 0 == sofar;
        }
    }

Log in to reply
 

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