Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save tratitude/432d446aa9904e935d7574081c5f4020 to your computer and use it in GitHub Desktop.
Save tratitude/432d446aa9904e935d7574081c5f4020 to your computer and use it in GitHub Desktop.
class Solution {
public:
int lengthOfLongestSubstring(string s) {
int i, j;
int maxLen=0;
int maxIndex=0;
int sLen = s.length();
int substringLen=0;
for(i=0; i<sLen; i++){
bool check[256] = {false};
substringLen = 1;
check[s[i]] = true;
for(j=i+1; j<sLen; j++){
if(!check[s[j]]){ // character not exit yet
check[s[j]] = true;
substringLen++;
}
else
break;
}
if(substringLen>maxLen){
maxLen = substringLen;
maxIndex = i;
}
}
return maxLen;
}
};
@tratitude
Copy link
Author

Need consider several cases, "", "c", others ascii characters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment