Skip to content
This repository was archived by the owner on Sep 20, 2023. It is now read-only.

Commit 798dcee

Browse files
committed
1170 accepted.
1 parent 0c757ca commit 798dcee

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,32 @@
11
package problem1170
22

3+
import "sort"
4+
35
func numSmallerByFrequency(queries []string, words []string) []int {
6+
n := len(words)
7+
ws := make([]int, n)
8+
for i, w := range words {
9+
ws[i] = f(w)
10+
}
11+
sort.Ints(ws)
12+
13+
res := make([]int, len(queries))
14+
for i, q := range queries {
15+
fq := f(q)
16+
res[i] = n - sort.Search(n, func(i int) bool { return fq < ws[i] })
17+
}
18+
19+
return res
20+
}
421

5-
return nil
22+
func f(s string) int {
23+
count := [26]int{}
24+
for _, b := range s {
25+
count[b-'a']++
26+
}
27+
i := 0
28+
for count[i] == 0 {
29+
i++
30+
}
31+
return count[i]
632
}

0 commit comments

Comments
 (0)