-2

可能重复:
如何找到给定字符串的最长重复子字符串

我想找到一个字符串中最长的重复子串。

    /**
This method will find the longest substring of a given string.
String given here is reassuring. 

 */
public String longestRepeatedSubstring()
{
    String longestRepeatedSubstring = "";
    for (int i = 0; i<text.length(); i++ )
    {
        String one = text.substring(0,i); 

        for(int o = 0; o<text.length();o++)
        {
            Sting two = text.substring(0,o);
            if(one.equals(two))
            {
                longestRepeatedSubstring = one;
            }

        }

    }
    return longestRepeatedSubstring; 
}
4

1 回答 1

0

你最好使用正则表达式。这里是:

/(?=((.+)(?:.*?\2)+))/s
于 2012-11-03T19:07:35.177 回答