Dashboard Temp Share Shortlinks Frames API

HTMLify

LeetCode - Design Parking System - Go
Views: 299 | Author: abh
 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
type ParkingSystem struct {
    big int
	medium int
	small int
}


func Constructor(big int, medium int, small int) ParkingSystem {
    var ps ParkingSystem
	ps.big = big
	ps.medium = medium
	ps.small = small
	return ps
}


func (this *ParkingSystem) AddCar(carType int) bool {
    switch carType {
		case 1:
			if this.big > 0 {
				this.big--
				return true
			}
		case 2:
			if this.medium > 0 {
				this.medium--
				return true
			}
		case 3:
			if this.small > 0 {
				this.small--
				return true
			}
		default:
			return false
	}
    return false
}


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