[C++] Shortest O(N) Solution with unordered_map


#1
vector<int> Solution::dNums(vector<int> &A, int B) {
    unordered_map<int, int> mp;
    int n=A.size(), i=0, j=0, cnt=0;
    while (j < B)
        cnt += !mp[A[j++]]++;
    vector<int> ans={cnt};
    while (j < n)
        ans.push_back(cnt += !mp[A[j++]]++ - !--mp[A[i++]]);
    return ans;
}