用递归算法写一个函数,求字符串最长连续字符的长度,比如aaaabbcc的长度为4,aabb的长度为2,ab的长度为1。
int findMaxRepeatStrLength(char* src, int curIndex) {
if (!src || *(src + curIndex) == '\0') {
return 0;
}
int len = 1;
int i = 1;
while (*(src + curIndex) == *(src + curIndex + i)) {
len++;
i++;
}
int nextLen = findMaxRepeatStrLength(src, curIndex + i);
return len > nextLen ? len : nextLen;
}