链接:https://leetcode-cn.com/problems/he-wei-sde-liang-ge-shu-zi-lcof/
代码
class Solution {
public:
vector<int> twoSum(vector<int>& nums, int target) {
int n = nums.size() - 1;
int i, j, tmp;
while (nums[n] >= target) n--;
i = 0, j = n;
while (i < j) {
tmp = nums[i] + nums[j];
if (tmp == target) {
return vector<int>{nums[i], nums[j]};
} else if (tmp > target) j--;
else i++;
}
return vector<int>();
}
};