forked from doocs/leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add solutions to lc problem: No.1603
No.1603.Design Parking System
- Loading branch information
Showing
6 changed files
with
171 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
solution/1600-1699/1603.Design Parking System/Solution.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
class ParkingSystem { | ||
public: | ||
vector<int> cnt; | ||
|
||
ParkingSystem(int big, int medium, int small) { | ||
cnt = {0, big, medium, small}; | ||
} | ||
|
||
bool addCar(int carType) { | ||
if (cnt[carType] == 0) return false; | ||
--cnt[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); | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
type ParkingSystem struct { | ||
cnt []int | ||
} | ||
|
||
func Constructor(big int, medium int, small int) ParkingSystem { | ||
return ParkingSystem{[]int{0, big, medium, small}} | ||
} | ||
|
||
func (this *ParkingSystem) AddCar(carType int) bool { | ||
if this.cnt[carType] == 0 { | ||
return false | ||
} | ||
this.cnt[carType]-- | ||
return true | ||
} | ||
|
||
/** | ||
* Your ParkingSystem object will be instantiated and called as such: | ||
* obj := Constructor(big, medium, small); | ||
* param_1 := obj.AddCar(carType); | ||
*/ |
13 changes: 5 additions & 8 deletions
13
solution/1600-1699/1603.Design Parking System/Solution.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters