We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent a90f6bc commit ad81353Copy full SHA for ad81353
leetcode/daily/2185/sol.go
@@ -0,0 +1,31 @@
1
+// https://leetcode.com/problems/counting-words-with-a-given-prefix/description/
2
+
3
+package main
4
5
+import "fmt"
6
7
+func prefixCount(words []string, pref string) int {
8
+ count := 0
9
+ for i := 0; i < len(words); i++ {
10
+ if isPrefix(pref, words[i]) {
11
+ count++
12
+ }
13
14
15
+ return count
16
+}
17
18
+func isPrefix(prefix, word string) bool {
19
+ n := len(prefix)
20
+ m := len(word)
21
22
+ prefixMatch := m >= n && word[:n] == prefix
23
24
+ return prefixMatch
25
26
27
+func main() {
28
+ words := []string{"pay", "attention", "practice", "attend"}
29
+ prefix := "at"
30
+ fmt.Println(prefixCount(words, prefix))
31
0 commit comments