-
Notifications
You must be signed in to change notification settings - Fork 3
/
2526.cpp
52 lines (47 loc) · 1.05 KB
/
2526.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
class DataStream {
public:
queue<int> q;
multiset<int> st;
long long v;
int K;
DataStream(int value, int k) {
v = value;
K = k;
}
bool consec(int num) {
q.push(num);
st.insert(num);
if (q.size() > K) {
int x = q.front();
q.pop();
st.erase(st.find(x));
}
if (q.size() < K) return false;
return *st.begin() == v && *st.rbegin() == v;
}
};
/**
* Your DataStream object will be instantiated and called as such:
* DataStream* obj = new DataStream(value, k);
* bool param_1 = obj->consec(num);
*/
class DataStream {
public:
int cnt = 0;
int value = -1;
int k;
DataStream(int value, int k) {
this->value = value;
this->k = k;
}
bool consec(int num) {
if (num == value) cnt++;
else cnt = 0;
return cnt >= k;
}
};
/**
* Your DataStream object will be instantiated and called as such:
* DataStream* obj = new DataStream(value, k);
* bool param_1 = obj->consec(num);
*/