-
Notifications
You must be signed in to change notification settings - Fork 481
/
1348.go
41 lines (34 loc) · 993 Bytes
/
1348.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
type TweetCounts struct {
tweets map[string][]int
}
func Constructor() TweetCounts {
this := new(TweetCounts)
this.tweets = make(map[string][]int)
return *this
}
func (this *TweetCounts) RecordTweet(tweetName string, time int) {
if this.tweets[tweetName] == nil {
this.tweets[tweetName] = []int{}
}
this.tweets[tweetName] = append(this.tweets[tweetName], time)
}
func (this *TweetCounts) GetTweetCountsPerFrequency(freq string, tweetName string, startTime int, endTime int) []int {
delta := 0
if freq == "minute" {
delta = 60
} else if freq == "hour" {
delta = 3600
} else {
delta = 60* 60 * 24
}
res := make([]int, (endTime - startTime)/delta + 1)
if this.tweets[tweetName] != nil {
for _, v := range this.tweets[tweetName] {
if v < startTime || v > endTime {
continue
}
res[(v - startTime)/delta]++
}
}
return res
}