Re: [閒聊] 每日LeetCode

作者: Rushia (みけねこ的鼻屎)   2023-05-29 20:46:05
https://leetcode.com/problems/design-parking-system/description/
1603. Design Parking System
設計一個停車場類別,他有大、中、小三種大小的車位,分別對應1、2、3的類型
1.ParkingSystem(int big, int medium, int small):初始化車位有幾個
2.bool addCar(int carType):carType類型的車可以停進去的話返回true。
Example 1:
Input
["ParkingSystem", "addCar", "addCar", "addCar", "addCar"]
[[1, 1, 0], [1], [2], [3], [1]]
Output
[null, true, true, false, false]
Explanation
ParkingSystem parkingSystem = new ParkingSystem(1, 1, 0);
parkingSystem.addCar(1); // return true because there is 1 available slot for
a big car
parkingSystem.addCar(2); // return true because there is 1 available slot for
a medium car
parkingSystem.addCar(3); // return false because there is no available slot
for a small car
parkingSystem.addCar(1); // return false because there is no available slot
for a big car. It is already occupied.
思路:
1.用一個陣列保存當前車位剩幾個
Java Code
作者: a9486l (a9486l)   2022-05-29 20:46:00
大師

Links booklink

Contact Us: admin [ a t ] ucptt.com