Quick actions

cmd+k|ctrl+k

Navigation

Languages

Design Parking System

Snippet info

Language

JavaScript

Visibility

public

Author

onifademola

Created

2021-10-09T23:41:23.338825Z

Updated

2021-10-18T16:16:03.399306Z

// https://leetcode.com/problems/design-parking-system/

class ParkingSystem {
    constructor (big, medium, small) {
        this.big = big;
        this.medium = medium;
        this.small = small;
    }
    
    addCar(carType) {
        switch (carType) {
            case 1:
                if (this.big === 0) return false;
                this.big--;
                return true;
            case 2:
                if (this.medium === 0) return false;
                this.medium--;
                return true;
            case 3:
                if (this.small === 0) return false;
                this.small--;
                return true;
            default:
                break;
        } 
    }
}

const parkingSystem = new ParkingSystem(1,1,0);
console.log(parkingSystem.addCar(1));
console.log(parkingSystem.addCar(2));
console.log(parkingSystem.addCar(3));
console.log(parkingSystem.addCar(1));
INFO