Skip to content

Commit 0f937ec

Browse files
authored
Create 1306.Jump-Game-III.cpp
1 parent 9d3bd7d commit 0f937ec

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
class Solution {
2+
int visited[50001];
3+
public:
4+
bool canReach(vector<int>& arr, int start)
5+
{
6+
if (start<0 || start>=arr.size())
7+
return false;
8+
if (arr[start]==0)
9+
return true;
10+
if (visited[start]==1)
11+
return false;
12+
13+
visited[start] = 1;
14+
if (canReach(arr, start-arr[start]))
15+
return true;
16+
17+
if (canReach(arr, start+arr[start]))
18+
return true;
19+
20+
visited[start] = 1;
21+
22+
return false;
23+
}
24+
};

0 commit comments

Comments
 (0)