```
public class Solution {
public int lengthOfLongestSubstring(String s) {
int[] map = new int[256];
int maxLen = 0, start=0, end=-1;
for(int i=0; i<s.length();i++){
int index = s.charAt(i);
if(map[index]>0){
maxLen = Math.max(maxLen, end-start+1);
start = Math.max(map[index], start);
}
map[index] = i+1;
end++;
}
return Math.max(maxLen, end-start+1);
}
}
```