Class ParkingSystem

java.lang.Object
g1601_1700.s1603_design_parking_system.ParkingSystem

public class ParkingSystem extends Object
1603 - Design Parking System.<p>Easy</p> <p>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.</p> <p>Implement the <code>ParkingSystem</code> class:</p> <ul> <li><code>ParkingSystem(int big, int medium, int small)</code> Initializes object of the <code>ParkingSystem</code> class. The number of slots for each parking space are given as part of the constructor.</li> <li><code>bool addCar(int carType)</code> Checks whether there is a parking space of <code>carType</code> for the car that wants to get into the parking lot. <code>carType</code> can be of three kinds: big, medium, or small, which are represented by <code>1</code>, <code>2</code>, and <code>3</code> respectively. <strong>A car can only park in a parking space of its</strong> <code>carType</code>. If there is no space available, return <code>false</code>, else park the car in that size space and return <code>true</code>.</li> </ul> <p><strong>Example 1:</strong></p> <p><strong>Input</strong> [&ldquo;ParkingSystem&rdquo;, &ldquo;addCar&rdquo;, &ldquo;addCar&rdquo;, &ldquo;addCar&rdquo;, &ldquo;addCar&rdquo;] [[1, 1, 0], [1], [2], [3], [1]]</p> <p><strong>Output:</strong> [null, true, true, false, false]</p> <p><strong>Explanation:</strong></p> <p>ParkingSystem parkingSystem = new ParkingSystem(1, 1, 0);</p> <p>parkingSystem.addCar(1); // return true because there is 1 available slot for a big car</p> <p>parkingSystem.addCar(2); // return true because there is 1 available slot for a medium car</p> <p>parkingSystem.addCar(3); // return false because there is no available slot for a small car</p> <p>parkingSystem.addCar(1); // return false because there is no available slot for a big car. It is already occupied.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>0 <= big, medium, small <= 1000</code></li> <li><code>carType</code> is <code>1</code>, <code>2</code>, or <code>3</code></li> <li>At most <code>1000</code> calls will be made to <code>addCar</code></li> </ul>
  • Constructor Details

    • ParkingSystem

      public ParkingSystem(int big, int medium, int small)
  • Method Details

    • addCar

      public boolean addCar(int carType)