一:题目描述
题目链接:. - 力扣(LeetCode)
二:算法原理
三:代码编写
vector<int> twoSum(vector<int>& price, int target)
{
vector<int> ret;
int left = 0, right = price.size()-1;
while(left < right)
{
if(price[left] + price[right] > target)
{
right--;
}
else if(price[left] + price[right] < target)
{
left++;
}
else
{
ret.push_back(price[left]);
ret.push_back(price[right]);
break;
}
}
return ret;
}