源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

华为面试题答案找出最大长度子字符串

  • 时间:2022-04-30 13:09 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:华为面试题答案找出最大长度子字符串
[u]复制代码[/u] 代码如下:
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; }
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部