LeetCode 5515 设计停车系统

    科技2022-07-12  132

    题目描述:

    代码(Java实现):

    class ParkingSystem { int big1; int medium1; int small1; public ParkingSystem(int big, int medium, int small) { big1 = big; medium1 = medium; small1 = small; } public boolean addCar(int carType) { if(carType == 1){ if(big1 > 0){ big1--; return true; } } if(carType == 2){ if(medium1 > 0){ medium1--; return true; } } if(carType == 3){ if(small1 > 0){ small1--; return true; } } return false; } } /** * Your ParkingSystem object will be instantiated and called as such: * ParkingSystem obj = new ParkingSystem(big, medium, small); * boolean param_1 = obj.addCar(carType); */

    结果:

    Processed: 0.011, SQL: 8