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 ss, mm, ll int }
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 }
|