1 题目描述
2 解题思路
这题很简单,顺着思路写就ok了
class AnimalShelf:
def __init__(self):
self.dog_list=[]
self.cat_list=[]
self.total_list=[]
def enqueue(self, animal: List[int]) -> None:
animal_num=animal[0]
animal_type=animal[1]
self.total_list.append([animal_num,animal_type])
if(animal_type==0):
self.cat_list.append([animal_num,animal_type])
elif(animal_type==1):
self.dog_list.append([animal_num,animal_type])
def dequeueAny(self) -> List[int]:
if(len(self.total_list)==0):
return([-1,-1])
ret_num,ret_type=self.total_list.pop(0)
if(ret_type==0):
self.cat_list.remove([ret_num,ret_type])
elif(ret_type==1):
self.dog_list.remove([ret_num,ret_type])
return(ret_num,ret_type)
def dequeueDog(self) -> List[int]:
if(len(self.dog_list)==0):
return([-1,-1])
ret_num,ret_type=self.dog_list.pop(0)
self.total_list.remove([ret_num,ret_type])
return(ret_num,ret_type)
def dequeueCat(self) -> List[int]:
if(len(self.cat_list)==0):
return([-1,-1])
ret_num,ret_type=self.cat_list.pop(0)
self.total_list.remove([ret_num,ret_type])
return(ret_num,ret_type)
# 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()