题目描述
输出描述:
对应每个测试案例,输出两个数,小的先输出。
class Solution {
public:
vector<int> FindNumbersWithSum(vector<int> array,int sum)
{
vector<int> num;
vector<int> out;
int len=array.size();
if(len < 2)return num;
int start=0;
int end=len-1;
int currentsum=0;
while(end>start)
{
currentsum=(array[start]+array[end]);
if(currentsum==sum)
{
num.push_back(array[start]);
num.push_back(array[end]);
return num;
}
else if(currentsum<sum)
start++;
else
end--;
}
return num;
}
};