public int lengthOfLongestSubstring(String s) {

```
if(s.equals(""))
return 0;
int i = -1;
int max =0;
int j =0;
int[] arr = new int[256];
Arrays.fill(arr,-1);
for(;j<s.length();j++) {
char c = s.charAt(j);
if(arr[c]>=i){
i= arr[c];
}
arr[c]=j;
if(max<j-i)
max = j-i;
}
return max;
}
```