Leetcode Problem 1603. Design Parking System

1603. Design Parking System

Leetcode Solutions

Array-based Parking Slot Tracking

  1. Initialize an array slots of size 3 in the constructor, where slots[0], slots[1], and slots[2] represent the number of available slots for big, medium, and small cars, respectively.
  2. In the addCar method, check if there is an available slot for the given carType by checking if slots[carType - 1] is greater than 0.
  3. If there is an available slot, decrement slots[carType - 1] by 1 to indicate that a slot has been taken and return true.
  4. If there are no available slots, return false without modifying the array.
UML Thumbnail

HashMap-based Parking Slot Tracking

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...