2つの数値のleecode合計

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

 

元の記事を141件公開しました 54のような 訪問数150,000以上

おすすめ

転載: blog.csdn.net/iamjingong/article/details/103774547