#55
Medium Algorithms Jump game
Array Dynamic Programming Greedy
40.5% acceptance
Jan 12, 2026
21615
1483
You are given an integer array nums. You are initially positioned at the array's first index, and each element in the array represents your maximum jump length at that position.
Return true if you can reach the last index, or false otherwise.
Solution
Rust
Time O(n)
Space O(1)
impl Solution {
pub fn can_jump(nums: Vec<i32>) -> bool {
let mut max_reach = 0;
for i in 0..nums.len() {
if i > max_reach {
return false;
}
max_reach = max_reach.max(i + nums[i] as usize);
if max_reach >= nums.len() - 1 {
return true;
}
}
true
}
}