Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

1603. Design Parking System leetcode solution in c++

class ParkingSystem {
public:
    ParkingSystem(int big, int medium, int small) {
        this->big = big;
        this->medium = medium;
        this->small = small;
    }
    
    bool addCar(int carType) {
        if(carType == 1 && big > 0)
        {
            big--;
            return true;
        }else if(carType == 2 && medium > 0)
        {
            medium--;
            return true;
        }else if(carType == 3 && small > 0)
        {
            small--;
            return true;
        }
        return false;
    }
private:
  int big;
  int medium;
  int small;  
};

/**
 * Your ParkingSystem object will be instantiated and called as such:
 * ParkingSystem* obj = new ParkingSystem(big, medium, small);
 * bool param_1 = obj->addCar(carType);
 */
Source by codejudge.blogspot.com #
 
PREVIOUS NEXT
Tagged: #Design #Parking #System #leetcode #solution
ADD COMMENT
Topic
Name
7+7 =