MCPcopy Create free account
hub / github.com/VanjaRo/LeetCode / strStr

Function strStr

tasks/28.go:7–20  ·  view source on GitHub ↗
(haystack string, needle string)

Source from the content-addressed store, hash-verified

5}
6
7func strStr(haystack string, needle string) int {
8 if len(needle) == 0 {
9 return 0
10 }
11 for ind := range haystack {
12 if len(haystack) < ind+len(needle) {
13 break
14 }
15 if haystack[ind:ind+len(needle)] == needle {
16 return ind
17 }
18 }
19 return -1
20}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected