blob: 153d9aa0e82428a4fe35d61a961c8e562a993b19 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
#include "leetcode.h"
class Solution {
public:
bool canJump(vector<int> &nums) {
int minJump = 0;
for (int i = nums.size() - 2; i >= 0; i--) {
minJump++;
if (nums[i] >= minJump)
minJump = 0;
}
if (minJump == 0)
return true;
else
return false;
}
};
int main() {
Solution obj;
vector<int> nums1 = {2, 3, 1, 1, 4}, nums2 = {3, 2, 1, 0, 4};
testBool(obj.canJump(nums1)); // true
testBool(obj.canJump(nums2)); // false
}
|