给定一个字符串 s ,请你找出其中不含有重复字符的 最长子串 的长度。
代码如下:
int lengthOfLongestSubstring(char* s) {
int len = strlen(s);
int map[127] = { 0 };
int l = 0;//leftSide
int r = 0;//rightSide
int max = 0;
while (r < len)
{
if (map[s[r]] == 0)
{
map[s[r++]]++;
}
else
{
map[s[l++]]--;
}
max = r - l > max ? r - l : max;
}
return max;
}
完整代码:https://github.com/frankRenlf/c_dailyWork.githttps://github.com/frankRenlf/c_dailyWork.git
里面有些乱,想测试就找到对应函数测试就行
有问题可在评论指出,觉得还行就给个赞和关注吧
也可以关注这个系列,后续也会有更新,和其他代码产出