public:
vector<int> twoSum(vector<int>& nums, int target) {
int size = nums.size();
vector<int> toRet;
unordered_map<int,pair<int,int>> myMap;
for(int i = 0; i < size; ++i){
myMap.emplace(nums[i],make_pair(nums[i],i));
}
for(int i = 0; i < size; ++i){
int toFind = target - nums[i];
if(myMap[toFind].first == toFind && myMap[toFind].second != i){
toRet.push_back(i);
toRet.push_back(myMap[toFind].second);
return toRet;
}
}
return toRet;
}
};
How do I make this run faster? I can't think of anything. Right now, it is slower than 47% of submissions. Could you please provide some hints?