Java – finds the longest prefix of string s, which is the substring inverted by string s
•
Java
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
二维码