You receive an array nums of non-negative integers. Begin at index 0, where the number stored at each position gives the farthest distance you may jump from that spot. Decide whether it is possible to arrive at the array's final position.
Input:
nums of size n, where n is between 1 and 10^4, inclusive. Every value in nums falls between 0 and 10^5, inclusive.Output:
true when the last index is reachable; otherwise, return false.Example:
Input: nums = [2,4,1,0,3]
Output: true
Explanation: Move 1 position from index 0 to index 1, then jump 3 positions to the final index.
Input: nums = [1,2,0,0,2]
Output: false
Explanation: You can get as far as index 3, but its jump limit is 0, preventing any move to the last index.
nums = [2, 4, 1, 0, 3]true
We start with the array nums = [2, 4, 1, 0, 3]. The last index (4) is our goal.
Input: 3,1,2,0,1
Output: true
nums = [2, 4, 1, 0, 3]true
We start with the array nums = [2, 4, 1, 0, 3]. The last index (4) is our goal.