C++ solution


  • 0
    K
    vector<vector<int>> threeSum1(vector<int>& nums){
        sort(nums.begin(),nums.end());
        for (int i = 0; i < nums.size(); ++i) {
            cout<<nums[i]<<endl;
        }
        vector<vector<int>> ts;
        for (int i = 0; i <nums.size(); ++i) {
            for (int j = i+1; j <nums.size() ; ++j) {
                for (int k = j+1; k <nums.size() ; ++k) {
                    if (nums[i]+nums[j]+nums[k]==0) {
                        vector<int> tmp={nums[i],nums[j],nums[k]};
                        ts.push_back(tmp);
                    }
                }
            }
        }
        sort(ts.begin(),ts.end());
        auto uniq=unique(ts.begin(),ts.end());
        ts.erase(uniq,ts.end());
        return ts;
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.