-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRLEIterator900.cpp
More file actions
34 lines (31 loc) · 804 Bytes
/
RLEIterator900.cpp
File metadata and controls
34 lines (31 loc) · 804 Bytes
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
class RLEIterator {
public:
vector<int>num;
RLEIterator(vector<int>& encoding) {
num = encoding;
}
int next(int n) {
//
while (n && !num.empty()) {
if (num[0] > n) {
num[0]-=n;
return num[1];
} else if (num[0] == n) {
int tmp = num[1];
num.erase(num.begin());
num.erase(num.begin());
return tmp;
} else {
n-=num[0];
num.erase(num.begin());
num.erase(num.begin());
}
}
return -1;
}
};
/**
* Your RLEIterator object will be instantiated and called as such:
* RLEIterator* obj = new RLEIterator(encoding);
* int param_1 = obj->next(n);
*/