Leetcode 1603. Design Parking System Posted on 2021-01-23 In LeetCode 題目12345Input["ParkingSystem", "addCar", "addCar", "addCar", "addCar"][[1, 1, 0], [1], [2], [3], [1]]Output[null, true, true, false, false] 解法思維123456789101112131415161718var ParkingSystem = function(big, medium, small) { this.big=big this.medium=medium this.small=small};ParkingSystem.prototype.addCar = function(carType) { if(carType==1){ this.big-=1 return this.big>=0 }else if(carType==2){ this.medium-=1 return this.medium>=0 }else if(carType==3){ this.small-=1 return this.small>=0 } } 123456var ParkingSystem = function(big, medium, small) { this.remainingSpaces = [big, medium, small];};ParkingSystem.prototype.addCar = function(carType) { return (this.remainingSpaces[carType - 1]--) > 0};