解题思路:
略
Python3代码:
# v0
class ParkingSystem:
def __init__(self, big: int, medium: int, small: int):
self.big = big
self.medium = medium
self.small = small
def addCar(self, carType: int) -> bool:
if carType == 1:
if self.big>0:
self.big -= 1
return True
else:
return False
elif carType == 2:
if self.medium > 0:
self.medium -= 1
return True
else:
return False
elif carType == 3:
if self.small > 0:
self.small -= 1
return True
else:
return False
# v1
class ParkingSystem:
def __init__(self, big: int, medium: int, small: int):
self.data = [0, big, medium, small]
def addCar(self, carType: int) -> bool:
if self.data[carType] == 0:
return False
else:
self.data[carType] -= 1
return True
# v2
class ParkingSystem:
def __init__(self, big: int, medium: int, small: int):
self.data = [0, big, medium, small]
def addCar(self, carType: int) -> bool:
self.data[carType] -= 1
return self.data[carType] >= 0
网友评论