Skip to content

Latest commit

 

History

History
40 lines (29 loc) · 750 Bytes

933. 最近的请求次数.md

File metadata and controls

40 lines (29 loc) · 750 Bytes

933. 最近的请求次数

题目传送门

点击这里

解题思路

一道简单的设计题,用队列来实现计数,找到索引处的值在t-3000的临界位置即可。

代码

type RecentCounter struct {
    queue []int
}


func Constructor() RecentCounter {
    return RecentCounter{
        queue : []int{},
    }
}


func (this *RecentCounter) Ping(t int) int {
    this.queue = append(this.queue, t)
    var index int 
    for this.queue[index] < t-3000 {
        index ++
    }
    return len(this.queue)-index
}

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