How to find repeating sequence of characters in a given array?

后端 未结 14 842
故里飘歌
故里飘歌 2020-12-02 12:42

My problem is to find the repeating sequence of characters in the given array. simply, to identify the pattern in which the characters are appearing.

          


        
14条回答
  •  没有蜡笔的小新
    2020-12-02 13:14

    Put all your character in an array e.x. a[]

    i=0; j=0;
    for( 0 < i < count ) 
    {
    if (a[i] == a[i+j+1])
        {++i;}
    else
        {++j;i=0;}
    }
    

    Then the ratio of (i/j) = repeat count in your array. You must pay attention to limits of i and j, but it is the simple solution.

提交回复
热议问题