class Solution {
public int lengthOfLongestSubstring(String s) {
if(s.length()==0)return 0;
Set<Character> set=new HashSet<Character>();
char[] c=s.toCharArray();
int res=0;
int start=0;
int end=0;
while(end<c.length){
char a=c[end];
end++;
while(set.contains(a)){
char b=c[start];
start++;
set.remove(b);
}
set.add(a);
res=Math.max(res,end-start);
}
return res;
}
}