#include <iostream>
#include <vector>
#include <map>
#include <set>
using namespace std;
class Solution {
public:
vector<int> twoSum(vector<int>& nums, int target)
{
unordered_map<int, int> hashtable;
for (int i = 0; i < nums.size(); ++i)
{
auto it = hashtable.find(target - nums[i]);
if (it != hashtable.end())
{
return {it->second, i};
}
hashtable[nums[i]] = i;
}
return {};
}
};
int main()
{
return 0;
}
#include <iostream>
#include <vector>
#include <unordered_map>
using namespace std;
class Solution
{
public:
vector<int> twoSum(vector<int> &nums, int target)
{
unordered_map<int, int> hashtable;
for (int i = 0; i < (int)nums.size(); ++i)
{
auto it = hashtable.find(target - nums[i]);
if (it != hashtable.end())
{
return {it->second, i};
}
hashtable[nums[i]] = i;
}
return {};
}
};
int main()
{
vector<int> nums{1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
vector<int> r = Solution().twoSum(nums, 5);
if (!r.empty())
cout << r[0] << ' ' << r[1] << endl;
return 0;
}