Skip to content

Commit bdb71fe

Browse files
authored
Create frog-jump-ii.cpp
1 parent c872cfb commit bdb71fe

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

C++/frog-jump-ii.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Time: O(n)
2+
// Space: O(1)
3+
4+
// greedy
5+
class Solution {
6+
public:
7+
int maxJump(vector<int>& stones) {
8+
if (size(stones) == 2) {
9+
return stones[1] - stones[0];
10+
}
11+
int result = 0;
12+
for (int i = 0; i + 2 < size(stones); ++i) {
13+
result = max(result, stones[i + 2] - stones[i]);
14+
}
15+
return result;
16+
}
17+
};

0 commit comments

Comments
 (0)