fix(canjump): change to uint

This commit is contained in:
miguel 2024-05-06 18:23:41 +01:00 committed by MSilva95
parent d9315ebdd7
commit df85068145
2 changed files with 9 additions and 9 deletions

View File

@ -1,8 +1,8 @@
### Can Jump
## Can Jump
Given an array of integers representing the maximum number of steps you can take forward from each position, implement the function `CanJump()` which takes an `integer slice` as input and returns a `boolean` value to determine if it's possible to reach the last index starting from the first index based on these maximum steps. The function should return `true` if it's possible to reach the last index and `false` otherwise.
Given an array of non-negative integers representing the maximum number of steps you can take forward from each position, implement the function `CanJump()` which takes a `[]uint` as input and returns a `boolean` value to determine if it's possible to reach the last index starting from the first index based on these maximum steps. The function should return `true` if it's possible to reach and stay at the last index without stepping out of the array and `false` otherwise.
> Note: The function only needs to consider positive numbers or zero in the array of steps. Also remember if the input has only one element that is the last position in the array so the function will return `true`.
> Note: Remember, if the input has only one element, that is the last position in the array so the function will return `true` but if the array is empty it returns `false`.
### Usage
@ -17,13 +17,13 @@ import (
)
func main() {
input1 := []int{2, 3, 1, 1, 4}
input1 := []uint{2, 3, 1, 1, 4}
fmt.Println(piscine.CanJump(input1))
input2 := []int{3, 2, 1, 0, 4}
input2 := []uint{3, 2, 1, 0, 4}
fmt.Println(piscine.CanJump(input2))
input3 := []int{0}
input3 := []uint{0}
fmt.Println(piscine.CanJump(input3))
}
```

View File

@ -6,12 +6,12 @@ import (
)
func main() {
input1 := []int{2, 3, 1, 1, 4}
input1 := []uint{2, 3, 1, 1, 4}
fmt.Println(piscine.CanJump(input1))
input2 := []int{3, 2, 1, 0, 4}
input2 := []uint{3, 2, 1, 0, 4}
fmt.Println(piscine.CanJump(input2))
input3 := []int{0}
input3 := []uint{0}
fmt.Println(piscine.CanJump(input3))
}