How to find the period of a string

前端 未结 5 1070
花落未央
花落未央 2021-02-03 12:58

I take a input from the user and its a string with a certain substring which repeats itself all through the string. I need to output the substring or its length AKA period.

5条回答
  •  醉梦人生
    2021-02-03 13:43

    You can do this in linear time and constant additional space by inductively computing the period of each prefix of the string. I can't recall the details (there are several things to get right), but you can find them in Section 13.6 of "Text algorithms" by Crochemore and Rytter under function Per(x).

提交回复
热议问题