Skip to content

Commit 8fb36ea

Browse files
aQuaaQua
authored andcommitted
819 accepted
1 parent 1aeea22 commit 8fb36ea

File tree

4 files changed

+59
-2
lines changed

4 files changed

+59
-2
lines changed
Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,50 @@
11
package problem0819
22

3+
import (
4+
"strings"
5+
)
6+
37
func mostCommonWord(paragraph string, banned []string) string {
8+
isBanned := make(map[string]bool)
9+
for _, b := range banned {
10+
isBanned[b] = true
11+
}
12+
13+
ss := split(paragraph)
14+
15+
count := make(map[string]int, len(ss))
16+
for _, s := range ss {
17+
if isBanned[s] {
18+
continue
19+
}
20+
count[s]++
21+
}
22+
23+
res := ""
24+
max := 0
25+
26+
for s, c := range count {
27+
if max < c {
28+
max = c
29+
res = s
30+
}
31+
}
32+
33+
return res
34+
}
35+
36+
func split(paragraph string) []string {
37+
p := replace(paragraph)
38+
p = strings.ToLower(p)
39+
return strings.Split(p, " ")
40+
}
41+
42+
func replace(s string) string {
43+
chars := []string{"!", "?", ",", "'", ";", "."}
44+
45+
for _, c := range chars {
46+
s = strings.Replace(s, c, "", -1)
47+
}
448

5-
return ""
49+
return s
650
}

Algorithms/0819.most-common-word/most-common-word_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,18 @@ var tcs = []struct {
1414
ans string
1515
}{
1616

17+
{
18+
"j. t? T. z! R, v, F' x! L; l! W. M; S. y? r! n; O. q; I? h; w. t; y; X? y, p. k! k, h, J, r? w! U! V; j' u; R! z. s. T' k. P? M' I' j! y. P, T! e; X. w? M! Y, X; G; d, X? S' F, K? V, r' v, v, D, w, K! S? Q! N. n. V. v. t? t' x! u. j; m; n! F, V' Y! h; c! V, v, X' X' t? n; N' r; x. W' P? W; p' q, S' X, J; R. x; z; z! G, U; m. P; o. P! Y; I, I' l' J? h; Q; s? U, q, x. J, T! o. z, N, L; u, w! u, S. Y! V; S? y' E! O; p' X, w. p' M, h! R; t? K? Y' z? T? w; u. q' R, q, T. R? I. R! t, X, s? u; z. u, Y, n' U; m; p? g' P? y' v, o? K? R. Q? I! c, X, x. r' u! m' y. t. W; x! K? B. v; m, k; k' x; Z! U! p. U? Q, t, u' E' n? S' w. y; W, x? r. p! Y? q, Y. t, Z' V, S. q; W. Z, z? x! k, I. n; x? z; V? s! g, U; E' m! Z? y' x? V! t, F. Z? Y' S! z, Y' T? x? v? o! l; d; G' L. L, Z? q. w' r? U! E, H. C, Q! O? w! s? w' D. R, Y? u. w, N. Z? h. M? o, B, g, Z! t! l, W? z, o? z, q! O? u, N; o' o? V; S! z; q! q. o, t! q! w! Z? Z? w, F? O' N' U' p? r' J' L; S. M; g' V. i, P, v, v, f; W? L, y! i' z; L? w. v, s! P?",
19+
[]string{"m", "q", "e", "l", "c", "i", "z", "j", "g", "t", "w", "v", "h", "p", "d", "b", "a", "r", "x", "n"},
20+
"y",
21+
},
22+
23+
// {
24+
// "isn't isn't isn",
25+
// []string{"hit"},
26+
// "isn't",
27+
// },
28+
1729
{
1830
"Bob hit a ball, the hit BALL flew far after it was hit.",
1931
[]string{"hit"},

Helper/buildProblemDir.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ func build(p problem) {
104104
var typeMap = map[string]string{
105105
"int": "0",
106106
"float64": "0",
107+
"string": "\"\"",
107108
"bool": "false",
108109
}
109110

Helper/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66

77
// 程序辅助设置
88
const (
9-
VERSION = "6.1.12"
9+
VERSION = "6.1.15"
1010
)
1111

1212
func main() {

0 commit comments

Comments
 (0)