if (str == null || str == string.Empty)
{
printf"Null or empty!!!!\n";
}
int max = 1;
int count = 1;
int number = 0;
char[] theChar=new char[str.Length];
theChar[number] = str[0];
for (int i = 1; i < str.Length; i++)
{
if (str[i] == str[i - 1])
{
count++;
if(max < count)
{
max=count;
number = 0;
theChar[number]=str[i];
}
else if (max == count)
{
number++;
theChar[number] = str[i];
}
}
if (str[i] != str[i - 1])
{
count = 1;
}
}
string[] strArray = new string[number+1];
for (int i = 0; i <= number; i++)
{
strArray[i] = new string(theChar[i], max);
}
return strArray;
}
寻找最长子串
最新推荐文章于 2023-02-27 16:54:55 发布