Leetcode: strStr - SUNDAY algorithm
Sunday algorithm is a variation of BM algorithm, which is used broadly in string comparation, and is faster and easier than KMP algorithm(usually 3-5 times!).
Naive thinking is just multiple X for n times, but this is absolutely not this question wants.
We need to make use of the calculation result in previous steps, since X^n = X^n/2 * X^n/2
What if n is odd? Then we need to multiple X one more times.
|
|