class Solution {
public:
vector<int> twoSum(vector<int>& nums, int target) {
vector<int> result;
unordered_map<int,int> hash;
for(int i=0;i<nums.size();i++)
{
int numToFind=targetnums[i];
if(hash.find(numToFind)!=hash.end())
{
result.push_back(i);
result.push_back(hash[numToFind]);
return result;
}
hash[nums[i]]=i;
}
return result;
}
};
13ms solution c++


@bidwell i am finding the number (int numToFind=targetnums[i]) in the hash. if it is there then it will push the result in the result else the
statement(hash[nums[i]]=i;) will add the current number to the hash. in this way hash will be updated.