Description
1 | Implement strStr(). |
Solution
The brute force is very easy to come up with, and the time complexity will be O(mn)
However, we can implement kmp to get O(n + m).
https://www.youtube.com/watch?v=BXCEFAzhxGY
1 | class Solution: |
1 | kmp array is the longest prefix - suffix array of pattern string. |