-
Notifications
You must be signed in to change notification settings - Fork 1
/
kWindowDuplicates.cpp
60 lines (42 loc) · 992 Bytes
/
kWindowDuplicates.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <iostream>
#include <unordered_set>
#include <vector>
#include <dequeue>
using namespace std ;
class KWindows
{
int _nDuplicates;
public:
KWindows(int nDuplciates)
: _nDuplicates(nDuplciates)
{}
~KWindows() {}
void nDuplictesByIteration( vector<int> list, int winSize )
{
if (winSize < list.size()) return;
dequeue<int> dq;
unordered_set<int> checkList;
int i;
for(i = 0; i < winSize; i++)
{
if ( !checkList.insert( list[i] ).second ) _nDuplicates++;
dq.push_back( list[i] );
}
int iteration = 1;
cout << "iteration 1 : " << _nDuplicates << endl;
for(int j = i + 1; j < list.size(); j++)
{
if ( checkList.find( dq.front() ) != checkList.end() )
_nDuplicates--;
dq.pop_front();
dq.push_back( list[i] );
if ( ! checkList.insert( list[i] ).second )
_nDuplicates++;
cout << "iteration " << iteration++ << ": " << _nDuplicates << endl;
}
}
};
int main(){
A a("hello");
return 0;
}