找出字符串中第一个匹配项的下标
解题思路:
func strStr(haystack string, needle string) int {
for i := 0; i < len(haystack)-len(needle)+1; i++ {
if haystack[i] == needle[0] && haystack[i:i+len(needle)] == needle {
return i
}
}
return -1
}复杂度分析
最后更新于