Implement strStr()
Input:
haystack = "hello", needle = "ll"
Output:
2Input:
haystack = "aaaaa", needle = "bba"
Output:
-1Analysis
Solution
Two loops
Use needle as pattern string, outer loop move n - m + 1 times, inner loop at most m times
Multiple Pointers - O(mn) time
Using string equals
Last updated