Skip to content

Commit 1208c6e

Browse files
committed
feat: add solutions to leetcode problem: No.1603
1 parent 17ab2a2 commit 1208c6e

File tree

4 files changed

+120
-2
lines changed

4 files changed

+120
-2
lines changed

solution/1600-1699/1603.Design Parking System/README.md

+41-1
Original file line numberDiff line numberDiff line change
@@ -47,22 +47,62 @@ parkingSystem.addCar(1); // 返回 false ,因为没有空的大车位,唯一
4747

4848
<!-- 这里可写通用的实现逻辑 -->
4949

50+
为每种车维护一个计数器,初始值为车位的数目。此后,每来一辆车,就将对应类型的计数器减 1。当计数器为 0 时,说明车位已满。
51+
5052
<!-- tabs:start -->
5153

5254
### **Python3**
5355

5456
<!-- 这里可写当前语言的特殊实现逻辑 -->
5557

5658
```python
59+
class ParkingSystem:
60+
61+
def __init__(self, big: int, medium: int, small: int):
62+
self.spaces = [big, medium, small]
63+
5764

65+
def addCar(self, carType: int) -> bool:
66+
if self.spaces[carType - 1] <= 0:
67+
return False
68+
self.spaces[carType - 1] -= 1
69+
return True
70+
71+
72+
# Your ParkingSystem object will be instantiated and called as such:
73+
# obj = ParkingSystem(big, medium, small)
74+
# param_1 = obj.addCar(carType)
5875
```
5976

6077
### **Java**
6178

6279
<!-- 这里可写当前语言的特殊实现逻辑 -->
6380

6481
```java
65-
82+
class ParkingSystem {
83+
84+
private int[] spaces = new int[3];
85+
86+
public ParkingSystem(int big, int medium, int small) {
87+
spaces[0] = big;
88+
spaces[1] = medium;
89+
spaces[2] = small;
90+
}
91+
92+
public boolean addCar(int carType) {
93+
if (spaces[carType - 1] <= 0) {
94+
return false;
95+
}
96+
--spaces[carType - 1];
97+
return true;
98+
}
99+
}
100+
101+
/**
102+
* Your ParkingSystem object will be instantiated and called as such:
103+
* ParkingSystem obj = new ParkingSystem(big, medium, small);
104+
* boolean param_1 = obj.addCar(carType);
105+
*/
66106
```
67107

68108
### **...**

solution/1600-1699/1603.Design Parking System/README_EN.md

+39-1
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,51 @@ parkingSystem.addCar(1); // return false because there is no available slot for
4747
### **Python3**
4848

4949
```python
50+
class ParkingSystem:
5051

52+
def __init__(self, big: int, medium: int, small: int):
53+
self.spaces = [big, medium, small]
54+
55+
56+
def addCar(self, carType: int) -> bool:
57+
if self.spaces[carType - 1] <= 0:
58+
return False
59+
self.spaces[carType - 1] -= 1
60+
return True
61+
62+
63+
# Your ParkingSystem object will be instantiated and called as such:
64+
# obj = ParkingSystem(big, medium, small)
65+
# param_1 = obj.addCar(carType)
5166
```
5267

5368
### **Java**
5469

5570
```java
56-
71+
class ParkingSystem {
72+
73+
private int[] spaces = new int[3];
74+
75+
public ParkingSystem(int big, int medium, int small) {
76+
spaces[0] = big;
77+
spaces[1] = medium;
78+
spaces[2] = small;
79+
}
80+
81+
public boolean addCar(int carType) {
82+
if (spaces[carType - 1] <= 0) {
83+
return false;
84+
}
85+
--spaces[carType - 1];
86+
return true;
87+
}
88+
}
89+
90+
/**
91+
* Your ParkingSystem object will be instantiated and called as such:
92+
* ParkingSystem obj = new ParkingSystem(big, medium, small);
93+
* boolean param_1 = obj.addCar(carType);
94+
*/
5795
```
5896

5997
### **...**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
class ParkingSystem {
2+
3+
private int[] spaces = new int[3];
4+
5+
public ParkingSystem(int big, int medium, int small) {
6+
spaces[0] = big;
7+
spaces[1] = medium;
8+
spaces[2] = small;
9+
}
10+
11+
public boolean addCar(int carType) {
12+
if (spaces[carType - 1] <= 0) {
13+
return false;
14+
}
15+
--spaces[carType - 1];
16+
return true;
17+
}
18+
}
19+
20+
/**
21+
* Your ParkingSystem object will be instantiated and called as such:
22+
* ParkingSystem obj = new ParkingSystem(big, medium, small);
23+
* boolean param_1 = obj.addCar(carType);
24+
*/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class ParkingSystem:
2+
3+
def __init__(self, big: int, medium: int, small: int):
4+
self.spaces = [big, medium, small]
5+
6+
7+
def addCar(self, carType: int) -> bool:
8+
if self.spaces[carType - 1] <= 0:
9+
return False
10+
self.spaces[carType - 1] -= 1
11+
return True
12+
13+
14+
# Your ParkingSystem object will be instantiated and called as such:
15+
# obj = ParkingSystem(big, medium, small)
16+
# param_1 = obj.addCar(carType)

0 commit comments

Comments
 (0)