class Solution {
public:
bool canJump(vector<int>& nums) {
if (nums.empty()) return false;
vector<bool> accessibility(nums.size(), false);
accessibility[0] = true;
for (int i = 0; i < nums.size(); ++i) {
if (accessibility[i]) {
for (int j = i+1; j < i+nums[i]; ++j) {
accessibility[j] = true;
}
}
else {
break;
}
}
return accessibility.back();
}
};
class Solution {
public:
bool canJump(vector<int>& nums) {
if (nums.empty()) return false;
int accessibility = 0;
for (int i = 0; i < nums.size(); ++i) {
if (i <= accessibility) {
accessibility = max(accessibility, i+nums[i]);
}
else {
break;
}
}
return accessibility >= nums.size()-1;
}
};
class Solution {
public:
bool canJump(vector<int>& nums) {
if (nums.empty()) return false;
int accessibility = 0, i = 0;
while (i <= accessibility && i < nums.size()) {
accessibility = max(accessibility, i+nums[i]);
i++;
}
return accessibility >= nums.size()-1;
}
};