forked from Rahul-skush/leetcode-solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1306_Jump Game III.cpp
More file actions
42 lines (38 loc) · 926 Bytes
/
1306_Jump Game III.cpp
File metadata and controls
42 lines (38 loc) · 926 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*
Leetcode problem no .- 1306
problem name - Jump Game III
Difficulty - Medium
*/
class Solution {
public:
bool fun(vector<int>& a,int start,char* memo){
bool c=false,d=false;
if(memo[start]=='G')
return true;
if(memo[start]=='B'){
return false;
}
memo[start]='B';
int left,right;
left=start-a[start];
right=start+a[start];
if(left>=0){
c=fun(a,left,memo);
}
if(right<a.size()){
d=fun(a,right,memo);
}
return(c||d);
}
bool canReach(vector<int>& a, int start) {
char memo[a.size()];
for(int i=0;i<a.size();i++){
if(a[i]==0){
memo[i]='G';
}
else
memo[i]='U';
}
return fun(a,start,memo);
}
};