class Solution {
public:
vector<int> twoSum(vector<int>& numbers, int target) {
int i=0;
int j=numbers.size()-1;
for(;i<numbers.size();i++)
{
while(numbers[i]+numbers[j]>target)
{
j--;
}
if(numbers[i]+numbers[j]==target)
break;
}
//每次枚举一个
vector<int>ans;
ans.push_back(i+1);
ans.push_back(j+1);
return ans;
}
};
LeetCode167
最新推荐文章于 2024-08-23 11:07:46 发布