167 Two Sum II - Input array is sorted(两数之和 II - 输入有序数组)
【题目】:链接
【代码】:
class Solution
{
public:
vector<int> twoSum(vector<int>& nums, int target)
{
vector<int> rets;
int high = nums.size() - 1;
int low = 0;
while(low != high)
{
int sum = nums[low] + nums[high];
if( sum == target)
{
rets.push_back(low + 1);
rets.push_back(high + 1);
return rets;
}
else if(sum > target)
--high;
else
++low;
}
return rets;
}
};