From 068efb54c750ca268479fd422137ac7cdaeb5f47 Mon Sep 17 00:00:00 2001 From: ilnarisrisov Date: Sun, 25 May 2025 01:17:38 +0500 Subject: [PATCH] check --- src/two-sum.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/two-sum.cpp diff --git a/src/two-sum.cpp b/src/two-sum.cpp new file mode 100644 index 0000000..45e0491 --- /dev/null +++ b/src/two-sum.cpp @@ -0,0 +1,26 @@ +#include +#define ARRAY_SIZE 5 + +bool two_sum( + const int nums[ARRAY_SIZE], + const int target, + std::size_t& index0, + std::size_t& index1 +) +{ + for(int i = 0; i < ARRAY_SIZE; i++) + { + for(int j = 0; j < ARRAY_SIZE; j++) + { + if(i == j) + continue; + if(nums[i]+nums[j] == target) + { + index0 = i; + index1 = j; + return true; + } + } + } + return false; +}; \ No newline at end of file