首页 > 其他分享 >LC167

LC167

时间:2022-09-01 11:55:24浏览次数:44  
标签:target nums int back vector ans LC167

vector<int> twoSum(vector<int>& nums, int target) {
    int l=0;
    int r=nums.size()-1;
    vector<int> ans;
    while(l<r){
        if(nums[l]+nums[r]>target){
            r--;
        }else if(nums[l]+nums[r]==target){
            ans.push_back(l+1);
            ans.push_back(r+1);
            break;
        }else{
            l++;
        }
    }
    return ans;
}

标签:target,nums,int,back,vector,ans,LC167
From: https://www.cnblogs.com/lwx11111/p/16646037.html

相关文章