feat: 55_jump_game
This commit is contained in:
parent
7e7e210169
commit
e07011a229
16
55_jump_game/main.cpp
Normal file
16
55_jump_game/main.cpp
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
#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;
|
||||||
|
}
|
||||||
|
};
|
Loading…
x
Reference in New Issue
Block a user