vector<int> twoSum(vector<int> &numbers, int target) {
vector<int> twoIndex;
map<int, int> numIndex;
for(int i = 0; i < numbers.size(); i++) {
int num = target - numbers[i];
if(!numIndex.count(num)) {
numIndex[numbers[i]] = i;
}
else {
twoIndex.push_back(numIndex[num]+1);
twoIndex.push_back(i+1);
return twoIndex;
}
}
}
用的map;似乎还可以用先排序在查找