Skip to content

Commit

Permalink
Create jumpgame.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
Manishak798 authored Nov 24, 2024
1 parent 6efaf53 commit 3c58438
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions arrays/jumpgame.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class Solution {
public:
bool canJump(vector<int>& nums) {
int maxIndex = 0;
for(int i=0; i<nums.size(); i++){
if(i > maxIndex){
return false;
}
maxIndex = max(maxIndex, i + nums[i]);
}
return true;
}
};

0 comments on commit 3c58438

Please sign in to comment.