-
시간복잡도: O(1)
-
알고리즘
구현
-
풀이설명
문제에서 제시한대로 구현하기만 하면 되는 문제입니다. 최대 수용량과 현재 수용량을 비교하기만 하면 됩니다.
-
소스코드
-
C++
class ParkingSystem { public: int cap[4], now[4] = {0,}; ParkingSystem(int big, int medium, int small) { cap[1] = big; cap[2] = medium; cap[3] = small; } bool addCar(int carType) { if(now[carType] < cap[carType]) { now[carType]++; return true; } return false; } };
-
Python
class ParkingSystem: cap = {} now = {} def __init__(self, big, medium, small): self.cap[3] = small self.cap[2] = medium self.cap[1] = big self.now[1] = 0 self.now[2] = 0 self.now[3] = 0 def addCar(self, carType): if self.now[carType] < self.cap[carType]: self.now[carType] += 1 return True else: return False
-
Java
class ParkingSystem { public int[] cap = new int[4]; public int[] now = {0, 0, 0, 0}; public ParkingSystem(int big, int medium, int small) { cap[1] = big; cap[2] = medium; cap[3] = small; } public boolean addCar(int carType) { if(now[carType] < cap[carType]) { now[carType]++; return true; } return false; } }
-