華為面試題謎底找出最年夜長度子字符串。本站提示廣大學習愛好者:(華為面試題謎底找出最年夜長度子字符串)文章只能為提供參考,不一定能成為您想要的結果。以下是華為面試題謎底找出最年夜長度子字符串正文
int findMaxSubstring(char* str)
{
int maxLength = 0;
int maxStartIndex = 0;
int curLength = 0;
int curStartIndex = 0;
bool isFind = 0;
for(unsigned int i = 0;i<strlen(str);i++)
{
if(str[i] >= 'a' && str[i] <= 'z')
{
if(isFind == 0)
{
isFind = 1;
curLength = 1;
curStartIndex = i;
}
else
{
curLength++;
}
}
else if (str[i] < 'a' || str[i] > 'z')
{
isFind = 0;
if(curLength > maxLength)
{
maxLength = curLength;
maxStartIndex = curStartIndex;
curLength = 0;
}
}
}
char *p = NULL;
p = &str[maxStartIndex];
while(*p >= 'a' && *p <= 'z')
{
putchar(*p);
p++;
}
return maxLength;
}