initial commit

This commit is contained in:
wt
2026-04-08 15:12:07 +07:00
commit 942e4e2dc1
30 changed files with 297 additions and 0 deletions
+1
View File
@@ -0,0 +1 @@
executable('jump', 'src/main.cpp', install: true)
+18
View File
@@ -0,0 +1,18 @@
#include <vector>
inline int jump(std::vector<int> &nums) {
int n = nums.size();
if (n <= 1) return 0;
int jumps = 0;
int current_end = 0;
int farthest = 0;
for (int i = 0; i < n - 1; i++) {
farthest = std::max(farthest, i + nums[i]);
if (i == current_end) {
jumps += 1;
current_end = farthest;
if (current_end >= n - 1) break;
}
}
return jumps;
}
+13
View File
@@ -0,0 +1,13 @@
#include <cassert>
#include <vector>
#include "jump.hpp"
int main() {
std::vector<int> nums = {2, 3, 1, 1, 4};
int output = jump(nums);
assert(output == 2);
nums = {2, 3, 0, 1, 4};
output = jump(nums);
assert(output == 2);
return 0;
}