```
``````
public int lengthOfLongestSubstring(String s) {
if(s.length()==0) return 0;
int i=0,j=0,ret=0;
boolean[] existed = new boolean[256];
while(i<s.length()){
if(existed[s.charAt(i)]){
if(i-j > ret) ret = i-j;
while(s.charAt(j)!=s.charAt(i)){
existed[s.charAt(j)] = false;
j++;
}
j++;
}
existed[s.charAt(i)] = true;
i++;
}
return (i-j>ret) ? i-j : ret;
}
```