luoheng
10/11/2019 - 1:49 PM

RecentCounter

type RecentCounter struct {
    A []int
}


func Constructor() RecentCounter {
    return RecentCounter{
        A: make([]int, 0),
    }
}


func (this *RecentCounter) Ping(t int) int {
    i := 0
    for i < len(this.A) {
        if t - this.A[i] > 3000 {
            i++
        } else {
            break
        }
    }
    this.A = this.A[i:]
    this.A = append(this.A, t)
    return len(this.A)
}


/**
 * Your RecentCounter object will be instantiated and called as such:
 * obj := Constructor();
 * param_1 := obj.Ping(t);
 */