Skip to content

Instantly share code, notes, and snippets.

@pinglunliao
Created April 13, 2019 14:52
Show Gist options
  • Save pinglunliao/f2e024ba28aa414640e3ebd45eead40e to your computer and use it in GitHub Desktop.
Save pinglunliao/f2e024ba28aa414640e3ebd45eead40e to your computer and use it in GitHub Desktop.
class Solution {
public:
vector<int> twoSum(vector<int>& nums, int target) {
multimap<int, int> nTable;
multimap<int, int>::iterator it;
vector<int> result;
for(int i = 0; i < nums.size(); i++) {
int c = target - nums[i];
nTable.insert(make_pair(nums[i], i));
it = nTable.find(c);
if(it != nTable.end() && i != it->second) {
if(it->first == nums[i]) {
result.push_back(it->second);
result.push_back(i);
return result;
}
result.push_back(i);
result.push_back(it->second);
return result;
}
}
return result;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment