class Solution {
public:
//双指针算法
vector<int> FindNumbersWithSum(vector<int> array,int sum) {
vector<int> res;
if(array.size()==0||array.size()==1)
return res;
int left=0,right=array.size()-1;
while(right>left){
if(array[left]+array[right]==sum){
res.push_back(array[left]);
res.push_back(array[right]);
break;
}
else if(array[left]+array[right]<sum){
left++;
}
else right--;
}
return res;
}
};
public:
//双指针算法
vector<int> FindNumbersWithSum(vector<int> array,int sum) {
vector<int> res;
if(array.size()==0||array.size()==1)
return res;
int left=0,right=array.size()-1;
while(right>left){
if(array[left]+array[right]==sum){
res.push_back(array[left]);
res.push_back(array[right]);
break;
}
else if(array[left]+array[right]<sum){
left++;
}
else right--;
}
return res;
}
};