Java – finds the longest prefix of string s, which is the substring inverted by string s

Is there any way to use the linear time algorithm to find the longest prefix of string s, which is the substring of the inversion of string s?

Solution

Knuth Morris Pratt algorithm is applied to search the given string (s) in the reverse string (T) At each iteration, it will find the longest prefix of S, that is, the suffix of T [1.. I] Then you just need to find the maximum length of these prefixes

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>