-
-
Notifications
You must be signed in to change notification settings - Fork 8.9k
/
Copy pathSolution.py
38 lines (32 loc) · 1.07 KB
/
Solution.py
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
class PhoneDirectory:
def __init__(self, maxNumbers: int):
"""
Initialize your data structure here
@param maxNumbers - The maximum numbers that can be stored in the phone directory.
"""
self.provided = [False] * maxNumbers
def get(self) -> int:
"""
Provide a number which is not assigned to anyone.
@return - Return an available number. Return -1 if none is available.
"""
for i in range(len(self.provided)):
if not self.provided[i]:
self.provided[i] = True
return i
return -1
def check(self, number: int) -> bool:
"""
Check if a number is available or not.
"""
return not self.provided[number]
def release(self, number: int) -> None:
"""
Recycle or release a number.
"""
self.provided[number] = False
# Your PhoneDirectory object will be instantiated and called as such:
# obj = PhoneDirectory(maxNumbers)
# param_1 = obj.get()
# param_2 = obj.check(number)
# obj.release(number)