Skip to content

Commit 76b5ee7

Browse files
author
Shuo
committed
A: String Matching in an Array
1 parent b540efa commit 76b5ee7

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

problems/string-matching-in-an-array/string_matching_in_an_array.go

+5-10
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,12 @@ import "strings"
44

55
func stringMatching(words []string) []string {
66
var ans []string
7-
ok := func(str string) bool {
8-
for _, word := range words {
9-
if word != str && strings.Contains(word, str) {
10-
return true
11-
}
12-
}
13-
return false
14-
}
157
for _, word := range words {
16-
if ok(word) {
17-
ans = append(ans, word)
8+
for _, val := range words {
9+
if val != word && strings.Contains(val, word) {
10+
ans = append(ans, word)
11+
break
12+
}
1813
}
1914
}
2015
return ans

0 commit comments

Comments
 (0)