Leetcode 379 Solution
This article provides solution to leetcode question 379 (design-phone-directory)
Access this page by simply typing in "lcs 379" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/design-phone-directory
Solution
class PhoneDirectory:
def __init__(self, maxNumbers: int):
self.used = set()
self.q = collections.deque()
for i in range(0, maxNumbers):
self.q.append(i)
def get(self) -> int:
if len(self.q):
v = self.q.popleft()
self.used.add(v)
return v
else:
return -1
def check(self, number: int) -> bool:
return number not in self.used
def release(self, number: int) -> None:
if number not in self.used:
return
self.used.remove(number)
self.q.append(number)
# 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)