forked from luliyucoordinate/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1366.go
More file actions
26 lines (24 loc) · 643 Bytes
/
Copy path1366.go
File metadata and controls
26 lines (24 loc) · 643 Bytes
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
func rankTeams(votes []string) string {
n := len(votes[0])
cnt := make([][]int, 26)
for i := 0; i < 26; i++ {
cnt[i] = make([]int, n + 1)
cnt[i][n] = i
}
for _, vote := range votes {
for i := 0; i < n; i++ {
cnt[vote[i] - 'A'][i]--
}
}
res := []byte(votes[0])
sort.Slice(res, func(a, b int) bool {
for i := 0; i <= n; i++ {
if cnt[res[a] - 'A'][i] == cnt[res[b] - 'A'][i] {
continue
}
return cnt[res[a] - 'A'][i] < cnt[res[b] - 'A'][i]
}
return true
})
return string(res)
}