go: add «45. Jump Game II»

URL:	https://leetcode.com/problems/jump-game-ii/
Signed-off-by: Matej Focko <me@mfocko.xyz>
This commit is contained in:
Matej Focko 2025-01-04 17:38:18 +01:00
parent 601d5a1f68
commit ad8b800a0b
Signed by: mfocko
SSH key fingerprint: SHA256:icm0fIOSJUpy5+1x23sfr+hLtF9UhY8VpMC7H4WFJP8

15
go/jump-game-ii.go Normal file
View file

@ -0,0 +1,15 @@
package main
func jump(nums []int) int {
jumps, end, furthest := 0, 0, 0
for i := 0; i < len(nums)-1; i++ {
furthest = max(furthest, i+nums[i])
if i == end {
jumps++
end = furthest
}
}
return jumps
}