Skip to content

Commit 51ee66b

Browse files
author
openset
committed
Add: sort
1 parent 63ba26f commit 51ee66b

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

problems/compare-strings-by-frequency-of-the-smallest-character/compare_strings_by_frequency_of_the_smallest_character.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
package problem1170
22

3+
import "sort"
4+
35
func numSmallerByFrequency(queries []string, words []string) []int {
46
ans, m := make([]int, len(queries)), make([]int, len(words))
57
for i, w := range words {
68
m[i] = f(w)
79
}
10+
sort.Ints(m)
811
for i, q := range queries {
912
t := f(q)
10-
for _, n := range m {
11-
if t < n {
12-
ans[i]++
13+
for j := len(m) - 1; j >= 0; j-- {
14+
if t >= m[j] {
15+
break
1316
}
17+
ans[i]++
1418
}
1519
}
1620
return ans

0 commit comments

Comments
 (0)