219. Contains Duplicate II

Given an array of integers and an integer k, find out whether there are two distinct indices i and j in the array such that nums[i] = nums[j]and the difference between i and j is at most k.

class Solution {
public:
    bool containsNearbyDuplicate(vector& nums, int k) {
        map > m = map >();
        for(int i=0;i v = vector();
                v.push_back(i);
                m[nums[i]] = v;
            }else{
                m[nums[i]].push_back(i);
            }
        }
        
        for (auto& x: m) {
            vector &v = x.second;
            if(v.size() <= 1) continue;
            for(int i=0;i

你可能感兴趣的:(219. Contains Duplicate II)