Created
April 13, 2019 14:52
-
-
Save pinglunliao/f2e024ba28aa414640e3ebd45eead40e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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