From 9a23232cb8414877a93d3a2c5214a0ed46840862 Mon Sep 17 00:00:00 2001 From: Luke Else Date: Thu, 20 Oct 2022 07:36:46 +0100 Subject: [PATCH] Fixed naive solution - Want to look at using a map to get a better lookup time - Could have it so that it looks for the remaining value to get to the target in a map --- C++/src/1. Two Sum/TwoSum.cpp | 4 +--- C++/src/main.cpp | 5 +++++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/C++/src/1. Two Sum/TwoSum.cpp b/C++/src/1. Two Sum/TwoSum.cpp index 51befca..7da6bcb 100644 --- a/C++/src/1. Two Sum/TwoSum.cpp +++ b/C++/src/1. Two Sum/TwoSum.cpp @@ -12,9 +12,7 @@ namespace TwoSum{ {//Loop through the dataset if (nums[i] + nums[j] == target) {//Check sum - { - return vector(i, j); - } + return vector() = {i, j}; } } } diff --git a/C++/src/main.cpp b/C++/src/main.cpp index 4705c67..40e81ee 100644 --- a/C++/src/main.cpp +++ b/C++/src/main.cpp @@ -1,5 +1,10 @@ #include +#include +#include "1. Two Sum/TwoSum.cpp" int main() { + std::vector nums = { 3,2,4 }; + TwoSum::Solution twoSum; + std::cout << twoSum.twoSum(nums, 6)[0]; } \ No newline at end of file