How to find the period of a string

前端 未结 5 1068
花落未央
花落未央 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:48

    Well if every character in the input string is part of the repeating substring, then all you have to do is store first character and compare it with rest of the string's characters one by one. If you find a match, string until to matched one is your repeating string.

提交回复
热议问题