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