0%

LeetCode-1603

题目

1603. 设计停车系统

结果

代码

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
type ParkingSystem struct {
s, m, l int // threshold
ss, mm, ll int // current status
}

func Constructor(big int, medium int, small int) ParkingSystem {
return ParkingSystem{
s: small,
m: medium,
l: big,
}
}

func (ps *ParkingSystem) AddCar(carType int) bool {
switch carType {
case 3:
if ps.ss+1 <= ps.s {
ps.ss++
return true
}
case 2:
if ps.mm+1 <= ps.m {
ps.mm++
return true
}
case 1:
if ps.ll+1 <= ps.l {
ps.ll++
return true
}
}
return false
}

/**
* Your ParkingSystem object will be instantiated and called as such:
* obj := Constructor(big, medium, small);
* param_1 := obj.AddCar(carType);
*/