if (rightmost >= size - 1) {
? ? return true;
}
rightmost = std::max(rightmost, idx + nums[idx]);
class Solution {
public:
bool canJump(vector<int>& nums) {
int size = nums.size();
int rightmost = 0;
for (int idx = 0; idx < size; ++idx) {
if (idx <= rightmost) {
rightmost = std::max(rightmost, idx + nums[idx]);
if (rightmost >= size - 1) {
return true;
}
}
}
return false;
}
};