Skip to content

Commit

Permalink
LeetCode/55.cc
Browse files Browse the repository at this point in the history
  • Loading branch information
userr2232 committed May 25, 2022
1 parent 894195b commit 31ede21
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions LeetCode/55.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class Solution {
public:
bool canJump(vector<int>& nums) {
if(nums.empty()) return true;
const int n = nums.size();
int goal = n-1;
for(int i = n-1; i >= 0; --i) {
if(i < goal && i+nums[i] >= goal)
goal = i;
if(goal == 0) return true;
}
return false;
}
};

0 comments on commit 31ede21

Please sign in to comment.