```
public int lengthOfLongestSubstring(String s) {
int[] arr = new int[128];
Arrays.fill(arr, -1);
int max = 0;
int beginIndex=0;
for(int i=0; i<s.length(); i++){
char c = s.charAt(i);
if(arr[c]>=beginIndex){
max = Math.max(max,i-beginIndex);
beginIndex = arr[c]+1;
}
arr[c]=i;
}
max = Math.max(max,s.length()-beginIndex);
return max;
}
```