2025-03-04 00:42:36 +08:00

17 lines
356 B
C++

#include <bits/stdc++.h>
using namespace std;
class Solution {
public:
bool canJump(vector<int>& nums) {
int farthest = 0;
for (int i = 0; i < nums.size() && i <= farthest; i++) {
farthest = max(farthest, i + nums[i]);
if (farthest >= nums.size() - 1) return true;
}
return false;
}
};