Problem: 3. 无重复字符的最长子串
思路
从几个方面展开
- 取最大值
- 查找重复
- 退回到重复点之后的那个字符
- 解决到达
*s == 0
之后count > countMax
的问题
解题方法
暴力解法
Code
int lengthOfLongestSubstring(char* s) {
char s1[50000], *p = s1;
int count = 0, countMax = 0;
while(*s != 0) {
for (char* q = s1; q != p; q++) {
if (*q == *s) {
if(count > countMax) {
countMax = count;
}
count = 0;
for(;p > q+1; p--) s--;
p = s1;
goto out;
}
}
*(p++) = *(s++);
count++;
out:;
}
if(count > countMax){
countMax = count;
}
return countMax;
}
一些碎碎念
为什么我还是做不到24ms解决这个问题。