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

This commit is contained in:
Luke Else 2022-10-20 07:36:46 +01:00
parent 414d968417
commit 9a23232cb8
2 changed files with 6 additions and 3 deletions

View File

@ -12,9 +12,7 @@ namespace TwoSum{
{//Loop through the dataset
if (nums[i] + nums[j] == target)
{//Check sum
{
return vector<int>(i, j);
}
return vector<int>() = {i, j};
}
}
}

View File

@ -1,5 +1,10 @@
#include <iostream>
#include <vector>
#include "1. Two Sum/TwoSum.cpp"
int main() {
std::vector<int> nums = { 3,2,4 };
TwoSum::Solution twoSum;
std::cout << twoSum.twoSum(nums, 6)[0];
}