forked from doocs/leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSolution.py
31 lines (25 loc) · 960 Bytes
/
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
class AnimalShelf:
def __init__(self):
self.cats = []
self.dogs = []
def enqueue(self, animal: List[int]) -> None:
if animal[1] == 0:
self.cats.insert(0, animal[0])
else:
self.dogs.insert(0, animal[0])
def dequeueAny(self) -> List[int]:
if len(self.dogs) == 0:
return self.dequeueCat()
if len(self.cats) == 0:
return self.dequeueDog()
return self.dequeueDog() if self.dogs[-1] < self.cats[-1] else self.dequeueCat()
def dequeueDog(self) -> List[int]:
return [-1, -1] if len(self.dogs) == 0 else [self.dogs.pop(), 1]
def dequeueCat(self) -> List[int]:
return [-1, -1] if len(self.cats) == 0 else [self.cats.pop(), 0]
# Your AnimalShelf object will be instantiated and called as such:
# obj = AnimalShelf()
# obj.enqueue(animal)
# param_2 = obj.dequeueAny()
# param_3 = obj.dequeueDog()
# param_4 = obj.dequeueCat()