-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1603.-Design-Parking-System.rs
49 lines (46 loc) · 1.12 KB
/
1603.-Design-Parking-System.rs
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
46
47
48
49
struct ParkingSystem {
big: i32,
medium: i32,
small: i32
}
impl ParkingSystem {
fn new(big: i32, medium: i32, small: i32) -> Self {
ParkingSystem {
big : big,
medium : medium,
small : small
}
}
fn add_car(&mut self, car_type: i32) -> bool {
match car_type {
1 => { // big
match self.big != 0 {
true => {
self.big -= 1;
true
},
false => false
}
},
2 => {
match self.medium != 0 {
true => {
self.medium -= 1;
true
},
false => false
}
},
3 => {
match self.small != 0 {
true => {
self.small -= 1;
true
},
false => false
}
},
_ => true
}
}
}