Return the zero-based index of the first exact occurrence of sub inside s. Return -1 when it does not occur. By convention, an empty sub matches at index 0.
Input / output
s: string, sub: stringExamples
s = "mississippi", sub = "iss" returns 1.s = "abcdef", sub = "gh" returns -1.Constraints
0 <= s.length, sub.length <= 100,000Follow-up When would KMP or another linear-time matcher be worth the preprocessing cost over a direct scan?