Given a string, find the length of the smallest string that does not contain repeating characters
The algorithm is crap, but it typed itself out
public int lengthOfLongestSubstring(String s) { int res = 0; for(int i = 0; i < s.length(); i++){ Set<Character > set = new HashSet<>(); set.add(s.charAt(i)); for(int j = i+1; j < s.length(); j++){ if(set.contains(s.charAt(j))){ break; }else{ set.add(s.charAt(j)); } } res = Math.max(res,set.size()); } return res; }}Copy the code