Skip to content

Commit

Permalink
feat(C++): Add 1603
Browse files Browse the repository at this point in the history
  • Loading branch information
euchangxian committed Oct 22, 2024
1 parent 9599aeb commit 0e2ac77
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
33 changes: 33 additions & 0 deletions C++/1603-DesignParkingSystem/Solution.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include <array>
#include <cstddef>

using namespace std;
class ParkingSystem {
private:
const int big = 1;
const int medium = 2;
const int small = 3;

std::array<int, 4> parkingLots;

public:
ParkingSystem(int big, int medium, int small) : parkingLots{{}} {
parkingLots[this->big] = big;
parkingLots[this->medium] = medium;
parkingLots[this->small] = small;
}

bool addCar(int carType) {
if (parkingLots[carType] == 0) {
return false;
}
--parkingLots[carType];
return true;
}
};

/**
* Your ParkingSystem object will be instantiated and called as such:
* ParkingSystem* obj = new ParkingSystem(big, medium, small);
* bool param_1 = obj->addCar(carType);
*/
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ Now solving in C++. Like it.
| 1590 | MakeSumDivisibleByP | [![C++](assets/c++.svg)](C++/1590-MakeSumDivisibleByP/Solution.cpp) |
| 1593 | SplitAStringIntoTheMaxNumberOfUniqueSubstrings | [![C++](assets/c++.svg)](C++/1593-SplitAStringIntoTheMaxNumberOfUniqueSubstrings/Solution.cpp) |
| 1598 | CrawlerLogFolder | [![C++](assets/c++.svg)](C++/1598-CrawlerLogFolder/Solution.cpp) |
| 1603 | DesignParkingSystem | [![C++](assets/c++.svg)](C++/1603-DesignParkingSystem/Solution.cpp) |
| 1605 | FindValidMatrixGivenRowAndColumnSums | [![C++](assets/c++.svg)](C++/1605-FindValidMatrixGivenRowAndColumnSums/Solution.cpp) |
| 1608 | SpecialArrayWithXElementsGreaterThanOrEqualX | [![C++](assets/c++.svg)](C++/1608-SpecialArrayWithXElementsGreaterThanOrEqualX/Solution.cpp) |
| 1631 | PathWithMinimumEffort | [![C++](assets/c++.svg)](C++/1631-PathWithMinimumEffort/Solution.cpp) |
Expand Down

0 comments on commit 0e2ac77

Please sign in to comment.