Skip to content

Commit 19d42c5

Browse files
solution for 55 problem
1 parent 3ff1f5c commit 19d42c5

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)