class Solution {
public int lengthOfLongestSubstring(String S) {
char[] s = S.toCharArray();
int[] cnt = new int[128];
int left = 0;
int res = 0;
for(int right = 0; right < s.length; right ++ ){
char c = s[right];
cnt[c] ++ ;
while(cnt[c] > 1){
cnt[s[left]] -- ;
left ++ ;
}
res = Math.max(res, right - left + 1);
}
return res;
}
}