剑指OFFER 和为S的两个数字
class Solution {
public:
vector<int> FindNumbersWithSum(vector<int> array,int sum) {
int left = 0;
int right = array.size()-1;
vector<int> v;//结果数组
int pro = INT_MAX;
while(left < right)
{
if(array[left] + array[right] > sum)
{
right--;
}else if(array[left] + array[right] < sum)
{
left++;
}else{
//只有满足乘积最小才添加到结果数组当中
if(array[left]*array[right]<pro)
{
v.clear();
pro = array[left]*array[right];
v.push_back(array[left]);
v.push_back(array[right]);
}
left++;
right--;
}
}
return v;
}
};