HTMLify

LeetCode - Design Parking System - Go
Views: 10 | Author: abh
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);
 */

Comments