Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SleimanJneidi/a25643f9f5755dcf3940 to your computer and use it in GitHub Desktop.
Save SleimanJneidi/a25643f9f5755dcf3940 to your computer and use it in GitHub Desktop.
public int lengthOfLongestSubstring(String s) {
if(s==null || s.length()==0)
return 0;
int max = Integer.MIN_VALUE;
for (int i = 0; i < s.length(); i++) {
int []charIndex = new int[127];
charIndex[s.charAt(i)]++;
int count = 1;
for (int j = i+1; j < s.length(); j++) {
char c = s.charAt(j);
int charCount = charIndex[c];
if(charCount>=1){
break;
}else{
charIndex[c]++;
count++;
}
}
max = Math.max(max,count);
}
return max;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment