2023-12-09 18:42:21 +08:00
< p > Given an array of non-negative integers < code > arr< / code > , you are initially positioned at < code > start< / code > index of the array. When you are at index < code > i< / code > , you can jump to < code > i + arr[i]< / code > or < code > i - arr[i]< / code > , check if you can reach < strong > any< / strong > index with value 0.< / p >
2022-03-27 18:27:43 +08:00
< p > Notice that you can not jump outside of the array at any time.< / p >
< p > < / p >
2023-12-09 18:42:21 +08:00
< p > < strong class = "example" > Example 1:< / strong > < / p >
2022-03-27 18:27:43 +08:00
< pre >
< strong > Input:< / strong > arr = [4,2,3,0,3,1,2], start = 5
< strong > Output:< / strong > true
< strong > Explanation:< / strong >
All possible ways to reach at index 3 with value 0 are:
index 5 -> index 4 -> index 1 -> index 3
index 5 -> index 6 -> index 4 -> index 1 -> index 3
< / pre >
2023-12-09 18:42:21 +08:00
< p > < strong class = "example" > Example 2:< / strong > < / p >
2022-03-27 18:27:43 +08:00
< pre >
< strong > Input:< / strong > arr = [4,2,3,0,3,1,2], start = 0
< strong > Output:< / strong > true
< strong > Explanation:
< / strong > One possible way to reach at index 3 with value 0 is:
index 0 -> index 4 -> index 1 -> index 3
< / pre >
2023-12-09 18:42:21 +08:00
< p > < strong class = "example" > Example 3:< / strong > < / p >
2022-03-27 18:27:43 +08:00
< pre >
< strong > Input:< / strong > arr = [3,0,2,1,2], start = 2
< strong > Output:< / strong > false
< strong > Explanation: < / strong > There is no way to reach at index 1 with value 0.
< / pre >
< p > < / p >
< p > < strong > Constraints:< / strong > < / p >
< ul >
< li > < code > 1 < = arr.length < = 5 * 10< sup > 4< / sup > < / code > < / li >
< li > < code > 0 < = arr[i] < arr.length< / code > < / li >
< li > < code > 0 < = start < arr.length< / code > < / li >
< / ul >