1603. 设计停车系统
1.题目
2.我的解决方案
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 and self.big > 0:
self.big -= 1
return True
elif carType == 1:
return False
if carType == 2 and self.medium > 0:
self.medium -= 1
return True
elif carType == 2:
return False
if carType == 3 and self.small > 0:
self.small -= 1
return True
elif carType == 3:
return False
- 时间复杂度:
O
(
1
)
O(1)
O(1)
- 空间复杂度:
O
(
1
)
O(1)
O(1)