-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path55.jump_game.cpp
37 lines (35 loc) · 903 Bytes
/
55.jump_game.cpp
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
//coding:utf-8
/*****************************************
Program: Jump Game
Description:
Author: [email protected]
Date: 2016-08-17 15:19:33
Last modified: 2016-08-17 15:19:54
GCC version: 4.9.3
*****************************************/
#include <vector>
class Solution {
bool helper(vector<int>& nums, int e){
if(e == 0)
return true;
if(nums[e - 1] >= 1)
return helper(nums, e - 1);
else{
if(e - 1 == 0)
return false;
for(int i = e - 2; i >= 0; i--){
if(nums[i] >= e - i){
if(i >= 1)
return helper(nums, i);
else
return true;
}
}
return false;
}
}
public:
bool canJump(vector<int>& nums) {
return helper(nums, nums.size() - 1);
}
};