```
public class Solution {
public int lengthOfLongestSubstring(String s) {
int[] m = new int[127];
char[] ch = s.toCharArray();
int max = 0;
int start = 0;
for (int i = 0; i < m.length; i++) {
m[i] = -1;
}
for (int i = 0; i < ch.length; i++) {
if (m[ch[i]] < 0) {
m[ch[i]] = i;
} else {
start = Math.max(start, m[ch[i]] + 1);
m[ch[i]] = i;
}
max = Math.max(max, i - start + 1);
}
return max;
}
```