-
Notifications
You must be signed in to change notification settings - Fork 3
/
379.cpp
35 lines (31 loc) · 813 Bytes
/
379.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
class PhoneDirectory {
public:
queue<int> q;
vector<bool> used;
PhoneDirectory(int maxNumbers) {
for (int i = 0; i < maxNumbers; i++) q.push(i);
used.resize(maxNumbers, false);
}
int get() {
if (q.empty()) return -1;
int number = q.front();
q.pop();
used[number] = true;
return number;
}
bool check(int number) {
return !used[number];
}
void release(int number) {
if (used[number] == false) return;
used[number] = false;
q.push(number);
}
};
/**
* Your PhoneDirectory object will be instantiated and called as such:
* PhoneDirectory* obj = new PhoneDirectory(maxNumbers);
* int param_1 = obj->get();
* bool param_2 = obj->check(number);
* obj->release(number);
*/