```
public int lengthOfLongestSubstring(String s) {
if(s=="" ) return 0;
int[] freq=new int[256];
int max=0;
int i=0,j=0;
int count=0;
while(j<s.length()){
if(freq[s.charAt(j++)]++ > 0) count++;
while(count>0 )
if(freq[s.charAt(i++)]-->1)
count--;
max=Math.max(max,j-i);
}
return max;
}
```

}