Created
May 13, 2018 08:58
-
-
Save tratitude/432d446aa9904e935d7574081c5f4020 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Need consider several cases, "", "c", others ascii characters.