7 line C# O(n) time & O(1) space


  • 0
    A
    public class Solution {
        public bool CanJump(int[] nums) {
            if (nums == null || nums.Length <= 1) return true;
            // keep the last reachable
            var len = nums.Length;
            var latest = len - 1;
            for (var i = len - 2; i >= 0; i--)
                if (latest - i <= nums[i])
                    latest = i;
            return latest == 0;
        }
    }
    

Log in to reply
 

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