forked from doocs/leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSolution.go
44 lines (39 loc) · 839 Bytes
/
Solution.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
42
43
44
type LogSystem struct {
logs []pair
d map[string]int
}
func Constructor() LogSystem {
d := map[string]int{
"Year": 4,
"Month": 7,
"Day": 10,
"Hour": 13,
"Minute": 16,
"Second": 19,
}
return LogSystem{[]pair{}, d}
}
func (this *LogSystem) Put(id int, timestamp string) {
this.logs = append(this.logs, pair{id, timestamp})
}
func (this *LogSystem) Retrieve(start string, end string, granularity string) (ans []int) {
i := this.d[granularity]
s, e := start[:i], end[:i]
for _, log := range this.logs {
t := log.ts[:i]
if s <= t && t <= e {
ans = append(ans, log.id)
}
}
return
}
type pair struct {
id int
ts string
}
/**
* Your LogSystem object will be instantiated and called as such:
* obj := Constructor();
* obj.Put(id,timestamp);
* param_2 := obj.Retrieve(start,end,granularity);
*/