```
public class Solution {
public int lengthOfLongestSubstring(String s) {
int max = 0, i =0 , j = 0,index;
int[] hm = new int[128];
while(j<s.length()){
if(hm[s.charAt(j)] == 0){
hm[s.charAt(j)] = j+1;
j++;
if((j-i) > max)
max = j-i;
}
else {
index = hm[s.charAt(j)];
hm[s.charAt(j)] = 0;
if (i < index)
i = index;
}
}
return max;
}
}
```