其他分享
首页 > 其他分享> > LC167

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
来源: https://www.cnblogs.com/lwx11111/p/16646037.html