
g0001_0100.s0055_jump_game.solution.go Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of leetcode-in-all Show documentation
Show all versions of leetcode-in-all Show documentation
104 LeetCode algorithm problem solutions
package s0055_jump_game
// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Dynamic_Programming #Greedy
// #Algorithm_II_Day_12_Dynamic_Programming #Dynamic_Programming_I_Day_4 #Udemy_Arrays
// #Big_O_Time_O(n)_Space_O(1) #2024_03_13_Time_48_ms_(71.95%)_Space_6.7_MB_(99.94%)
func canJump(nums []int) bool {
if len(nums) == 1 {
return true
}
jumpsNeeded := 1
for i := len(nums) - 2; i >= 0; i-- {
if nums[i] < jumpsNeeded {
jumpsNeeded += 1
} else {
jumpsNeeded = 1
}
}
return jumpsNeeded == 1
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy