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:
parent
414d968417
commit
9a23232cb8
@ -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};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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];
|
||||
}
|
Loading…
Reference in New Issue
Block a user