-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjump_game.cpp
More file actions
38 lines (30 loc) · 776 Bytes
/
jump_game.cpp
File metadata and controls
38 lines (30 loc) · 776 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
class Solution {
public:
/**
* @param A: A list of integers
* @return: The boolean answer
*/
// f[i] A[0...i - 1] can reach the last one
bool canJump(vector<int> A) {
// write you code here
int len = A.size();
if (len == 0) {
return true;
}
if (A[0] == 0) {
return false;
}
vector<bool> dp(len + 1, false);
dp[0] = true;
dp[1] = true;
for (int i = 2; i < len + 1; i++) {
for(int j = 1; j < i; j++) {
if (dp[j] && A[j - 1] + j >= i) {
dp[i] = true;
break;
}
}
}
return dp[len];
}
};