水题。直接暴力枚举,当然记得返回的下标是从1开始的。
class Solution {
public:
vector<int> twoSum(vector<int> &numbers, int target) {
vector<int> ans;
for(int i = 0; i < numbers.size(); i++){
for(int j = i+1; j < numbers.size(); j++){
if(numbers[i] + numbers[j] == target){
ans.push_back(i+1);
ans.push_back(j+1);
}
}
}
return ans;
}
};