Design Parking System LeetCode solution in Python

1
# Runtime: 111 ms (Top 92.4%) | Memory: 16.70 MB (Top 96.9%)
2

3

4
class ParkingSystem:
5
def __init__(self, big: int, medium: int, small: int):
6
self.vehicle = [big, medium, small]
7

8
def addCar(self, carType: int) -> bool:
9
if carType == 1:
10
if self.vehicle[0] > 0:
11
self.vehicle[0] -= 1
12
return True
13
elif carType == 2:
14
if self.vehicle[1] > 0:
15
self.vehicle[1] -= 1
16
return True
17
elif carType == 3:
18
if self.vehicle[2] > 0:
19
self.vehicle[2] -= 1
20
return True
21
return False

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0