You are given an array of integers nums. Each element nums[i] represents the maximum jump length from position i.
Your task is to determine if you can reach the last index starting from the first index.
You may assume that:
nums are non-negative.Return true if the last index is reachable, false otherwise.
[2, 2, 0, 1]
True
From index 0, you can jump to index 1 or 2. Jumping to index 1 allows you to jump to the last index (index 3). Thus, you can reach the last index.
[2, 2, 0, 0, 1]
False
From index 0, you can jump to index 1 or 2. However, from both index 1 and 2, you cannot reach the last index (index 4) because index 3 is a dead end. Thus, you cannot reach the last index.
[0]
True
The array has only one element, so the starting position is also the last position. You are already at the last index.
[2, 2, 0, 1]
True