Leetcode Note: Go - Number of Recent Calls
Number of Recent Calls - LeetCode
https://leetcode.com/problems/number-of-recent-calls/
- Go 言語で取り組んだメモ
回答
Number of Recent Calls - LeetCode
https://leetcode.com/problems/number-of-recent-calls/solution/
Go - LeetCode Discuss
https://leetcode.com/problems/number-of-recent-calls/discuss/726473/Go
type RecentCounter struct {
q []int
}
func Constructor() RecentCounter {
return RecentCounter{[]int{}}
}
func (this *RecentCounter) Ping(t int) int {
this.q = append(this.q, t)
for i, val := range this.q {
if val >= t - 3000 {
this.q = this.q[i:]
break
}
}
return len(this.q)
}
/**
* Your RecentCounter object will be instantiated and called as such:
* obj := Constructor();
* param_1 := obj.Ping(t);
*/