j********g 发帖数: 244 | 1 刚开始用,有的时候是很work的。有的时候,不知道为什么,说有好些test case没有
通过,上面的Output和expected说不一致,可我用自己的vs编译一下算出来的Output和
expected确实一致的啊。想问一下大家碰到它都是100% work的嘛? |
b******v 发帖数: 1493 | 2 一般这时候是你程序有bug,例如数组越界, uninitialized variable等造成不同运行
环境下输出结果不一样
【在 j********g 的大作中提到】 : 刚开始用,有的时候是很work的。有的时候,不知道为什么,说有好些test case没有 : 通过,上面的Output和expected说不一致,可我用自己的vs编译一下算出来的Output和 : expected确实一致的啊。想问一下大家碰到它都是100% work的嘛?
|
i**********e 发帖数: 1145 | |
j********g 发帖数: 244 | 4 谢谢两位
Longest Substring Without Repeating Characters
int lengthOfLongestSubstring(string s) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
int n = s.length();
int i = 0, j = 0;
int maxLen = 0;
bool exist[256] = {false};
int len = 0, k;
while(j < n){
exist[int(s[j]-'0')] = true;
i = j+1;
while(!exist[int(s[i]-'0')])
{
exist[int(s[i]-'0')] = true;
i++;
}
len = i-j;
if(len > maxLen)
maxLen = len;
for(k = 0; k<256; k++)
exist[k] = false;
j++;
}
return maxLen;
} |
i**********e 发帖数: 1145 | 5 index out of bound at this line:
while(!exist[int(s[i]-'0')])
change it to:
while(i < n && !exist[int(s[i]-'0')]) |
j********g 发帖数: 244 | 6 哇 一针见血。。。 现在可以了。谢谢大牛。
【在 i**********e 的大作中提到】 : index out of bound at this line: : while(!exist[int(s[i]-'0')]) : change it to: : while(i < n && !exist[int(s[i]-'0')])
|