首页 > 代码库 > 219. Contains Duplicate II 超时

219. Contains Duplicate II 超时

class Solution {
public:
bool containsNearbyDuplicate(vector<int>& nums, int k) {
int len=nums.size();
bool flag=false;
multimap<int ,int> mulm;
for(int i=0;i<len;i++)
{
mulm.insert(make_pair(nums[i],i));
}
multimap<int,int>::iterator it1=mulm.begin();
multimap<int ,int>::iterator it2=it1;
it2++;
for(;it2 !=mulm.end();it1++,it2++)
{
if((it2->first ==it1->first)&& (it2->second - it1->first<=k))
{
flag=true;
return true;
}

}
return false;
}

};

219. Contains Duplicate II 超时