-
Notifications
You must be signed in to change notification settings - Fork 0
/
Design Parking System.kt
44 lines (40 loc) · 1.11 KB
/
Design Parking System.kt
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
class ParkingSystem(private val big: Int,
private val medium: Int,
private val small: Int) {
private var bigCount = 0
private var smallCount = 0
private var mediumCount = 0
fun addCar(carType: Int): Boolean {
return when (carType) {
1 -> {
if (bigCount < big) {
bigCount++
return true
} else {
return false
}
}
2 -> {
if (mediumCount < medium) {
mediumCount++
return true
} else {
return false
}
}
else -> {
if (smallCount < small) {
smallCount++
return true
} else {
return false
}
}
}
}
}
/**
* Your ParkingSystem object will be instantiated and called as such:
* var obj = ParkingSystem(big, medium, small)
* var param_1 = obj.addCar(carType)
*/