题解 | #两数之和#
两数之和
http://www.nowcoder.com/practice/20ef0972485e41019e39543e8e895b7f
class Solution {
public:
/**
*
* @param numbers int整型vector
* @param target int整型
* @return int整型vector
*/
vector<int> twoSum(vector<int>& numbers, int target) {
int i,j,k;
int start;
int end;
vector<int>test(2);
for(i=0;i<=numbers.size()-1;i++){
start=numbers[i];
end=target-start;
for(j=i+1;j<=numbers.size()-1;j++){
if(end==numbers[j]){
test[0]=i+1;
test[1]=j+1;
}
}
}
return test;// write code here
}
};