LeetCode Q55 Jump Game
Given an array of non-negative integers nums
, you are initially positioned at the first index of the array.
Each element in the array represents your maximum jump length at that position.
Determine if you are able to reach the last index.
- First, initialize end is 0, it makes sure that we jump to max position later.
- Initialize maxPosition = 0, it keep looking for max position
- Traverse the nums array
- if we ever found end is smaller than current index, that means nums[end] is 0, we return false
- Updating maxPostion, find max between maxPosition and current index + current number
- let end = maxPosition if we reach end
1 | public boolean canJump(int[] nums) { |