deno.land / x / masx200_leetcode_test@10.6.5 / check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence / index.go

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
package index
import "strings"
func isPrefixOfWord(sentence string, searchWord string) int { var index = FindIndex(strings.Split(sentence, " "), func(el string) bool { return strings.HasPrefix(el, searchWord) }) if index < 0 { return index } else { return index + 1 }}
//func FindIndex[S ~[]T, T any](items S, f func(el T) bool) int {func FindIndex(items []string, f func(el string) bool) int { for i, el := range items { if f(el) { return i } } return -1}
masx200_leetcode_test

Version Info

Tagged at
a year ago