I have noticed the duplicated problem, why it still not work? Could some one help me?
vector<vector<int> > threeSum(vector<int> &num) {
// IMPORTANT: Please reset any member data you declared, as
// the same Solution instance will be reused for each test case.
vector<vector<int> > re;//store the result
vector<int> v;
map<int,int>m;// put num into map.
for(int i=0;i<num.size();i++){
if(m.find(num[i])==m.end())m[num[i]]=1;
else m[num[i]]=m[num[i]]+1;// eg if 1 appear twice, then m[1]=2
}
sort(num.begin(),num.end());//sort num
for(int i=0;i<num.size();i++)
for(int j=i+1;j<num.size();j++)
{ //num[i] is the smallest,num[j] is the middle,-num[i]-num[j] is the largest
//num[i] is the smallest,so it must smaller than 0
if(num[i]>0)break;
v.clear();
m[num[i]]--;
m[num[j]]--;
if(m.find(-num[i]-num[j])!=m.end()&&m.find(-num[i]-num[j])->second>0&&(-num[i]-num[j])>=num[j])
{v.push_back(num[i]);v.push_back(num[j]);v.push_back(-num[i]-num[j]);re.push_back(v);
while(i<num.size()-1&&num[i]==num[i+1])i++;}
m[num[i]]++;
m[num[j]]++;
}
return re;
}