3. Longest Substring Without Repeating Characters
class Solution {
public:
int i;
int lengthOfLongestSubstring(string s) {
int j;
int c;
int count=1;
if(s=="")return 0;
bool dj=true;//"abca"
for(i=0;i<s.length();i++){//string起点遍历
dj=true;
for(j=i+1;j<s.length();j++)//末点遍历
{
for(c=i;c<j;c++)
{if(s[c]==s[j]){
dj=false;
break;}
}
if(!dj)
break;
count=(count<(j-i+1)?(j-i+1):count);
}
}
return count;
}
};
注意:第一先写思维的流程图;第二注意用例测试的特殊性,“”,“bbbbb”,