LeetCode - Problems - Algorithms - 1603. Design Parking System
Problem Description
Design a parking system for a parking lot.
The parking lot has three kinds of parking spaces: big, medium, and small, with a fixed number of slots for each size.
Implement the ParkingSystem class:
- ParkingSystem(int big, int medium, int small) Initialized object of the ParkingSystem class. The number of slots for each parking space are given as part of the constructor.
- bool addCar(int carType) Checks whether there is a parking space of carType for the car that wants to get into the parking lot. carType can be of three kinds: big, medium, or small, which are represented by 1, 2, 3 respectibely. A car can only part in a parking space of its carType. If there is no space available, return false, else park the car in that size space and return true.
Example:
Constraints:
My Solution (Python)
class ParkingSystem(object):
def __init__(self, big, medium, small):
"""
:type big: int
:type medium: int
:type small: int
"""
self.big = big
self.medium = medium
self.small = small
def addCar(self, carType):
"""
:type carType: int
:rtype: bool
"""
if carType == 1:
if self.big <= 0:
return False
else:
self.big -= 1
return True
elif carType == 2:
if self.medium <= 0:
return False
else:
self.medium -= 1
return True
elif carType == 3:
if self.small <= 0:
return False
else:
self.small -= 1
return True
'Problem solving > Algorithms' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[LeetCode] 1684. Count the Number of Consistent Strings (Python) (0) | 2021.01.10 |
---|---|
[LeetCode] 1678. Goal Parser Interpretation (Python) (0) | 2021.01.10 |
[LeetCode] 1528. Shuffle String (Python) (0) | 2021.01.10 |
[LeetCode] 1512. Number of Good Pairs (Python) (0) | 2021.01.10 |
[LeetCode] 1470. Shuffle the Array (Python) (0) | 2021.01.10 |