Skip to content

Commit e178a59

Browse files
committed
Add solution #1603
1 parent 6940c81 commit e178a59

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 1,412 LeetCode solutions in JavaScript
1+
# 1,413 LeetCode solutions in JavaScript
22

33
[https://leetcodejavascript.com](https://leetcodejavascript.com)
44

@@ -1237,6 +1237,7 @@
12371237
1599|[Maximum Profit of Operating a Centennial Wheel](./solutions/1599-maximum-profit-of-operating-a-centennial-wheel.js)|Medium|
12381238
1600|[Throne Inheritance](./solutions/1600-throne-inheritance.js)|Medium|
12391239
1601|[Maximum Number of Achievable Transfer Requests](./solutions/1601-maximum-number-of-achievable-transfer-requests.js)|Hard|
1240+
1603|[Design Parking System](./solutions/1603-design-parking-system.js)|Easy|
12401241
1657|[Determine if Two Strings Are Close](./solutions/1657-determine-if-two-strings-are-close.js)|Medium|
12411242
1668|[Maximum Repeating Substring](./solutions/1668-maximum-repeating-substring.js)|Easy|
12421243
1669|[Merge In Between Linked Lists](./solutions/1669-merge-in-between-linked-lists.js)|Medium|
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* 1603. Design Parking System
3+
* https://leetcode.com/problems/design-parking-system/
4+
* Difficulty: Easy
5+
*
6+
* Design a parking system for a parking lot. The parking lot has three kinds of parking
7+
* spaces: big, medium, and small, with a fixed number of slots for each size.
8+
*
9+
* Implement the ParkingSystem class:
10+
* - ParkingSystem(int big, int medium, int small) Initializes object of the ParkingSystem class.
11+
* The number of slots for each parking space are given as part of the constructor.
12+
* - bool addCar(int carType) Checks whether there is a parking space of carType for the car that
13+
* wants to get into the parking lot. carType can be of three kinds: big, medium, or small, which
14+
* are represented by 1, 2, and 3 respectively. A car can only park in a parking space of its
15+
* carType. If there is no space available, return false, else park the car in that size space
16+
* and return true.
17+
*/
18+
19+
/**
20+
* @param {number} big
21+
* @param {number} medium
22+
* @param {number} small
23+
*/
24+
var ParkingSystem = function(big, medium, small) {
25+
this.spaces = { 1: big, 2: medium, 3: small };
26+
};
27+
28+
/**
29+
* @param {number} carType
30+
* @return {boolean}
31+
*/
32+
ParkingSystem.prototype.addCar = function(carType) {
33+
if (this.spaces[carType] > 0) {
34+
this.spaces[carType]--;
35+
return true;
36+
}
37+
return false;
38+
};

0 commit comments

Comments
 (0)