class Solution {
public:
vector<int> twoSum(vector<int>& numbers, int target) {
int l = 0, r = numbers.size() - 1;
while (l < r)
{
int sum = numbers[l] + numbers[r];
if (sum == target)
{
return { l + 1, r + 1 };
}
else if (sum > target)
{
r--;
}
else
{
l++;
}
}
return { -1, -1 };
}
};
LeetCode167. 两数之和 II - 输入有序数组
最新推荐文章于 2024-04-13 15:30:51 发布