Skip to content

Commit 06ab8ae

Browse files
authored
Update and rename canJump.cpp to jump-game.cpp
1 parent aa896f4 commit 06ab8ae

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

C++/canJump.cpp

-13
This file was deleted.

C++/jump-game.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Time: O(n)
2+
// Space: O(1)
3+
4+
class Solution {
5+
public:
6+
bool canJump(vector<int>& nums) {
7+
int reachable = 0;
8+
for (int i = 0; i <= reachable && i < nums.size(); ++i) {
9+
reachable = max(reachable, i + nums[i]);
10+
}
11+
return reachable >= nums.size() - 1;
12+
}
13+
};

0 commit comments

Comments
 (0)