class AnimalShelf:
def __init__(self):
self.dog = []
self.cat = []
#self.index = 0
def enqueue(self, animal: List[int]) -> None:
#self.index += 1
#templist = [self.index,animal]
if animal[1] == 0:
self.cat.append(animal[0])
else:
self.dog.append(animal[0])
def dequeueAny(self) -> List[int]:
if self.dog == [] and self.cat == []:
return [-1,-1]
elif self.dog == []:
return [self.cat.pop(0),0]
elif self.cat == []:
return [self.dog.pop(0),1]
else:
if self.cat[0] < self.dog[0]:
return [self.cat.pop(0),0]
else:
return [self.dog.pop(0),1]
return
def dequeueDog(self) -> List[int]:
if self.dog == []:
return [-1,-1]
else:
return [self.dog.pop(0),1]
def dequeueCat(self) -> List[int]:
if self.cat == []:
return [-1,-1]
else:
return [self.cat.pop(0),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()
Leetcode刷题记录——面试题 03.06. 动物收容所
最新推荐文章于 2021-04-17 21:31:57 发布