Find the smallest period of input string in O(n)?

后端 未结 5 541
渐次进展
渐次进展 2020-12-29 15:24

Given the following problem :

Definition :

Let S be a string over alphabet Σ .S\' is the smallest period of S

5条回答
  •  醉酒成梦
    2020-12-29 15:54

    See if this solution works for O(n). I used rotation of strings.

    public static int stringPeriod(String s){
    
        String s1= s;
        String s2= s1;
    
        for (int i=1; i 

    The complete program is available in this github repository

提交回复
热议问题