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('canJump', 'src/main.cpp', install: true)
+12
View File
@@ -0,0 +1,12 @@
#include <algorithm>
#include <vector>
inline bool canJump(std::vector<int> &nums) {
int max_reach = 0;
for (int i = 0; i < int(nums.size()); i++) {
if (i > max_reach) return false;
max_reach = std::max(max_reach, i + nums[i]);
if (max_reach >= int(nums.size()) - 1) return true;
}
return true;
}
+16
View File
@@ -0,0 +1,16 @@
#include <cassert>
#include <iostream>
#include <vector>
#include "canJump.hpp"
int main() {
std::vector<int> nums = {2, 3, 1, 1, 4};
bool k = canJump(nums);
std::cout << k << std::endl;
assert(k == true);
nums = {3, 2, 1, 0, 4};
k = canJump(nums);
std::cout << k << std::endl;
assert(k == false);
return 0;
}