```
public int lengthOfLongestSubstring(String s) {
int[] hash = new int[256];
int max = 0;
int left = 0, right = 0;
while(right < s.length() ){
hash[s.charAt(right)]--;
while(hash[s.charAt(right)] < -1) // here to check duplicate
{
hash[s.charAt(left)] ++;
left ++;
}
right++;
max = Math.max(right - left, max);
}
return max;
}**bolded text**
```