C++ map不含重复项:
class Solution {
public:
vector<int> twoSum(vector<int>& nums, int target) {
map<int,int> a;
vector<int> r(2);
for(int i = 0;i<nums.size();i++){
if(a.count(target-nums[i])>0){
r[0] = i;
r[1] = a[target-nums[i]];
break;
}
a[nums[i]]=i;
}
return r;
}
};