-
Notifications
You must be signed in to change notification settings - Fork 502
/
c.go
49 lines (46 loc) · 729 Bytes
/
c.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
45
46
47
48
49
package main
import "sort"
func peopleIndexes(mat [][]string) (ans []int) {
isSubset := func(a, b []int) bool {
i, n := 0, len(a)
j, m := 0, len(b)
for {
if i == n {
return true
}
if j == m {
return false
}
x, y := a[i], b[j]
if x < y {
return false
} else if x > y {
j++
} else {
i++
j++
}
}
}
sid := map[string]int{}
ids := make([][]int, len(mat))
for i, row := range mat {
for _, s := range row {
if sid[s] == 0 {
sid[s] = len(sid) + 1
}
ids[i] = append(ids[i], sid[s])
}
sort.Ints(ids[i])
}
o:
for i, a := range ids {
for j, b := range ids {
if j != i && isSubset(a, b) {
continue o
}
}
ans = append(ans, i)
}
return
}