Skip to content

Commit 4716012

Browse files
authored
Merge pull request #2581 from aadil42/patch-53
2 parents fd994a6 + 6c75be4 commit 4716012

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

Diff for: javascript/1603-design-parking-system.js

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/**
2+
* https://leetcode.com/problems/design-parking-system/
3+
* @class ParkingSystem
4+
* @param {number} big
5+
* @param {number} medium
6+
* @param {number} small
7+
*/
8+
class ParkingSystem {
9+
constructor(big, medium, small) {
10+
this.isBigRemaining = big;
11+
this.isMediumRemaining = medium;
12+
this.isSmallRemaining = small;
13+
}
14+
15+
/**
16+
* Time O(1) | Space O(1)
17+
* @param {number} carType
18+
* @return {boolean}
19+
*/
20+
addCar(carType) {
21+
const isBigCarAvailable = (carType === 1 && this.isBigRemaining > 0);
22+
if(isBigCarAvailable) {
23+
this.isBigRemaining -= 1;
24+
return true;
25+
}
26+
const isMediumCarAvailable = (carType === 2 && this.isMediumRemaining > 0);
27+
if(isMediumCarAvailable) {
28+
this.isMediumRemaining -= 1;
29+
return true;
30+
}
31+
const isSmallCarAvailable = (carType === 3 && this.isSmallRemaining > 0);
32+
if(isSmallCarAvailable) {
33+
this.isSmallRemaining -= 1;
34+
return true;
35+
}
36+
return false;
37+
}
38+
}
39+
40+
41+
/**
42+
* Your ParkingSystem object will be instantiated and called as such:
43+
* var obj = new ParkingSystem(big, medium, small)
44+
* var param_1 = obj.addCar(carType)
45+
*/

0 commit comments

Comments
 (0)