func stringSearch(haystack, needle string) int { var ( n = len(needle) t [256]int ) for i := 0; i < n; i++ { t[needle[i]] = i + 1 } end := len(haystack) for lo := 0; ; { hi := lo + n switch { case hi < end: case hi == end && haystack[lo:] == needle: return lo default: return -1 } if haystack[lo:hi] == needle { return lo } tip := haystack[hi] lo = hi + 1 + t[tip] } }
To receive a hint, submit unfixed code.