leetcode之数组中找出三个数之和为规定值

这个题可以用set里面套vector 进行去重,起初以为需要重载运算符,其实不用,

所以挺简单的:

class Solution {
public:
    vector > threeSum(vector &num) {
        vector> v;
        set > hash;
        int n=num.size();
        sort(num.begin(),num.end());
        for(int i=0;i tem;
            tem.push_back(num[i]);
            tem.push_back(num[j]);
            tem.push_back(num[k]);
            hash.insert(tem);
            }
        }
        for(auto it=hash.begin();it!=hash.end();it++)
            v.push_back(*it);
        return v;
    }
};


你可能感兴趣的:(leetcode)