面试题答案
一键面试package main
import (
"bytes"
"fmt"
)
func findNeedleInHaystack(haystack, needle []byte) int {
return bytes.Index(haystack, needle)
}
你可以通过如下方式调用:
func main() {
haystack := []byte("hello world")
needle := []byte("world")
result := findNeedleInHaystack(haystack, needle)
fmt.Println(result)
}