1603. Design Parking System Easy

@problem@discussion
#Design#Simulation#Counting



1/**
2 * [1603] Design Parking System
3 *
4 * 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.
5 * Implement the ParkingSystem class:
6 * 
7 * 	ParkingSystem(int big, int medium, int small) Initializes object of the ParkingSystem class. The number of slots for each parking space are given as part of the constructor.
8 * 	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, and 3 respectively. A car can only park 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.
9 * 
10 *  
11 * Example 1:
12 * 
13 * Input
14 * ["ParkingSystem", "addCar", "addCar", "addCar", "addCar"]
15 * [[1, 1, 0], [1], [2], [3], [1]]
16 * Output
17 * [null, true, true, false, false]
18 * Explanation
19 * ParkingSystem parkingSystem = new ParkingSystem(1, 1, 0);
20 * parkingSystem.addCar(1); // return true because there is 1 available slot for a big car
21 * parkingSystem.addCar(2); // return true because there is 1 available slot for a medium car
22 * parkingSystem.addCar(3); // return false because there is no available slot for a small car
23 * parkingSystem.addCar(1); // return false because there is no available slot for a big car. It is already occupied.
24 * 
25 *  
26 * Constraints:
27 * 
28 * 	0 <= big, medium, small <= 1000
29 * 	carType is 1, 2, or 3
30 * 	At most 1000 calls will be made to addCar
31 * 
32 */
33pub struct Solution {}
34
35// problem: https://leetcode.com/problems/design-parking-system/
36// discuss: https://leetcode.com/problems/design-parking-system/discuss/?currentPage=1&orderBy=most_votes&query=
37
38// submission codes start here
39
40struct ParkingSystem {
41        false
42    }
43
44
45/** 
46 * `&self` means the method takes an immutable reference.
47 * If you need a mutable reference, change it to `&mut self` instead.
48 */
49impl ParkingSystem {
50
51    fn new(big: i32, medium: i32, small: i32) -> Self {
52        
53    }
54    
55    fn add_car(&self, car_type: i32) -> bool {
56        
57    }
58}
59
60/**
61 * Your ParkingSystem object will be instantiated and called as such:
62 * let obj = ParkingSystem::new(big, medium, small);
63 * let ret_1: bool = obj.add_car(carType);
64 */
65
66// submission codes end
67
68#[cfg(test)]
69mod tests {
70    use super::*;
71
72    #[test]
73    fn test_1603() {
74    }
75}
76


Back
© 2025 bowen.ge All Rights Reserved.