funcConstructor(n int) SeatManager { var a = SeatManager{make(map[int]*seat, n), make([]int, n)} for i := 0; i < n; i++ { id := i + 1 a.seats[id] = &seat{id, 1} a.isFrees[i] = id // 初始化 } return a }
func(this *SeatManager) Reserve() int { sort.Ints(this.isFrees) top := this.isFrees[0] this.seats[top].isFree = 0 this.isFrees = this.isFrees[1:] return top }