思路:参考剑指OFFER课本
a[nSmall],a[nBig]
若总和<nTarget,nSmall++
若总和>nTarget,nBig--
若总和==nTarget,找到,并break
class Solution {
public:
vector<int> FindNumbersWithSum(vector<int> array,int sum) {
int nSmall=0,nBig = array.size()-1;
vector<int> vecResult;
if(array.size() ==0)
return vecResult;
while(nSmall<nBig)
{
if(array[nSmall]+array[nBig] <sum)
nSmall++;
else if(array[nSmall]+array[nBig] > sum)
nBig--;
else
{
vecResult.push_back(array[nSmall]);
vecResult.push_back(array[nBig]);
break;
}
}
return vecResult;
}
};