Created
October 17, 2015 15:50
-
-
Save SleimanJneidi/a25643f9f5755dcf3940 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
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