-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathq55.cpp
More file actions
33 lines (30 loc) · 721 Bytes
/
q55.cpp
File metadata and controls
33 lines (30 loc) · 721 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
#include "Common.h"
class Solution {
public:
// bool canJump(vector<int>& nums) {
// int n = nums.size();
// if(n == 0) return 1;
// bool sol = 1;
// for(int i = 1; i < n; ++i){
// if(!sol) sol = 0;
// else if(){
// }
// }
// }
bool canJump(vector<int>& A) {
int n = A.size();
int i = 0;
for (int reach = 0; i < n && i <= reach; ++i){
reach = max(i + A[i], reach);
cout << "i = " << i << endl;
cout << "i + A[i] = " << i + A[i] << endl;
cout << "reach = " << reach << endl;
}
return i == n;
}
};
int main(){
Solution sol;
vector<int> a{2,3,0,1};
cout << sol.canJump(a) << endl;
}