其他分享
首页 > 其他分享> > Leetcode1 - 10

Leetcode1 - 10

作者:互联网

 

1. 两数之和

class Solution {
public:
    vector<int> twoSum(vector<int>& nums, int target) {
        vector<int> v;
        for(int i = 0;i < nums.size();i++){
            for(int j = i;j < nums.size();j++){
                if(i != j && nums[i] + nums[j] == target){
                    v.push_back(i);
                    v.push_back(j);
                }
            }
        }
        return v;
    }
};

  

 

标签:10,target,nums,int,Leetcode1,back,++,vector
来源: https://www.cnblogs.com/wsjhs/p/14023780.html