Skip to content

Commit 8be66fe

Browse files
authored
Merge pull request larissalages#41 from aayushi-kunwar13/master
solution for 55 problem of leetcode
2 parents 4159537 + 19d42c5 commit 8be66fe

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

leetcode/cpp/Array/55.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//Best approach that is O(n) time complexity and O(1) space complexity
2+
3+
class Solution {
4+
public:
5+
bool canJump(vector<int>& nums) {
6+
int last = nums.length() - 1;
7+
for (int i = nums.length() - 1; i >= 0; i--) {
8+
if (i + nums[i] >= last) {
9+
last = i;
10+
}
11+
}
12+
return last ;
13+
}
14+
};

0 commit comments

Comments
 (0)