We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent f1e45b7 commit 388e17dCopy full SHA for 388e17d
1 file changed
jump-game/se6816.java
@@ -0,0 +1,27 @@
1
+class Solution {
2
+ public boolean canJump(int[] nums) {
3
+ boolean[] visited= new boolean[nums.length];
4
+ dfs(visited, nums, 0);
5
+ return visited[nums.length - 1];
6
+ }
7
+ public void dfs(boolean[] visited, int[] nums, int target) {
8
+ if(visited[nums.length -1]) {
9
+ return;
10
11
+ if(visited[target]) {
12
13
14
+
15
+ visited[target] = true;
16
17
+ int maxDist = nums[target];
18
+ for(int i = maxDist; i > 0; i--) {
19
+ int nextIdx = target + i;
20
+ if(nextIdx > nums.length - 1) {
21
+ continue;
22
23
24
+ dfs(visited, nums, nextIdx);
25
26
27
+}
0 commit comments