```
public class Solution {
public int lengthOfLongestSubstring(String s) {
HashSet<Character> hash = new HashSet<Character>();
int n = s.length();
int max = 0;
for(int i = 0; i < n; i++){
int j = i;
int an = 0;
while(j < n&&hash.add(s.charAt(j))){
j++;
an++;
}
max = Math.max(max, an);
hash.clear();
}
return max;
}
```

}