Manacher's Algorithm - Longest Palindromic Substring

Manacher's Algorithm for String Palindromes

Algorithm step

Now enter the steps to update P[]:

The first step is to initialize P[0]=0.

The second step, when i<strlen(str), execute the third step, otherwise end

The third step is to judge the value of P[id]+id=mx>i, and if it is false, perform the fourth step. Otherwise, go to step 5.

The fourth step, initialize P[i]=0, and execute while(str[i+P[i]+1] == str[iP[i]-1]) ++P[i]; i++, get all Find P[i].

The fifth step, if mx-i> P[j] , execute the sixth step, otherwise execute the seventh step.

The sixth step, P[i] = P[j], at this time, P[i] has been obtained, go back to the second step.

The seventh step, at this time P[i]>=mx-i, initialize P[i]=mx-i, and execute while(str[i+P[i]+1] == str[iP[i]- 1]) ++P[i]; i++, get the required P[i], go back to the second step.


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326224502&siteId=291194637