From d447823c3c24ae89b7502ad246548b353e3decdf Mon Sep 17 00:00:00 2001 From: IlyaKlyunev Date: Thu, 5 Dec 2024 22:39:14 +0500 Subject: [PATCH 1/2] added two-sum.cpp --- "\357\200\242two-sum.cpp" | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 "\357\200\242two-sum.cpp" diff --git "a/\357\200\242two-sum.cpp" "b/\357\200\242two-sum.cpp" new file mode 100644 index 0000000..4089653 --- /dev/null +++ "b/\357\200\242two-sum.cpp" @@ -0,0 +1,25 @@ +#include "two-sum.hpp" + +#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 - 1; i++) + { + for(int j = i+1; j < ARRAY_SIZE; j++) + { + if(nums[i]+nums[j] == цель) + { + index0 = i; + индекс1 = j; + return true; + } + } + } + return false; +}; From f8914cd407af4ec6a3140ef1bf7842ca10e85b14 Mon Sep 17 00:00:00 2001 From: IlyaKlyunev Date: Mon, 9 Dec 2024 18:09:30 +0500 Subject: [PATCH 2/2] =?UTF-8?q?Update=20=EF=80=A2two-sum.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "\357\200\242two-sum.cpp" | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git "a/\357\200\242two-sum.cpp" "b/\357\200\242two-sum.cpp" index 4089653..111a83a 100644 --- "a/\357\200\242two-sum.cpp" +++ "b/\357\200\242two-sum.cpp" @@ -6,17 +6,17 @@ const int nums[ARRAY_SIZE], const int target, std::size_t& index0, - std::size_t и index1 + std::size_t& index1 ) { for(int i = 0; i < ARRAY_SIZE - 1; i++) { for(int j = i+1; j < ARRAY_SIZE; j++) { - if(nums[i]+nums[j] == цель) + if(nums[i]+nums[j] == target) { index0 = i; - индекс1 = j; + index1 = j; return true; } }