Skip to content

Commit 03f47fc

Browse files
authored
Create 1306. Jump Game III (#1079)
2 parents 03a3e8c + dc0f81f commit 03f47fc

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

1306. Jump Game III

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution {
2+
public boolean canReach(int[] arr, int start) {
3+
if (start < 0 || start >= arr.length || arr[start] < 0) {
4+
return false;
5+
}
6+
if (arr[start] == 0) {
7+
return true;
8+
}
9+
int jumpDistance = arr[start];
10+
arr[start] = -1; // Mark as visited
11+
return canReach(arr, start + jumpDistance) || canReach(arr, start - jumpDistance);
12+
}
13+
}

0 commit comments

Comments
 (0)