-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution1817.go
More file actions
59 lines (48 loc) · 1.12 KB
/
solution1817.go
File metadata and controls
59 lines (48 loc) · 1.12 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package solution1817
// ============================================================================
// 1817. Finding the Users Active Minutes
// URL: https://leetcode.com/problems/finding-the-users-active-minutes/
// ============================================================================
func findingUsersActiveMinutesV1(logs [][]int, k int) []int {
var t int
var id int
uam := make(map[int]map[int]int)
for _, log := range logs {
id = log[0]
t = log[1]
if uam[id] == nil {
uam[id] = make(map[int]int)
}
uam[id][t]++
}
output := make([]int, k)
for i := 1; i <= k; i++ {
var c int
for _, m := range uam {
if i == len(m) {
c++
}
}
output[i-1] = c
}
return output
}
func findingUsersActiveMinutesV2_copilot(logs [][]int, k int) []int {
uam := make(map[int]map[int]struct{})
for _, log := range logs {
id := log[0]
t := log[1]
if uam[id] == nil {
uam[id] = make(map[int]struct{})
}
uam[id][t] = struct{}{}
}
output := make([]int, k)
for _, times := range uam {
activeMinutes := len(times)
if activeMinutes <= k {
output[activeMinutes-1]++
}
}
return output
}