1、无重复字符的最长子串
自己用java实现的算法
public int lengthOfLongestSubstring(String s) {
int length = 0;
char[] chars = s.toCharArray(); Map<Character, Set<Character>> map = new LinkedHashMap<>();
for (int i = 0; i < chars.length; i++) {
char c = chars[i];
Set<Character> set = new HashSet<>();
for (int j = i; j < chars.length; j++) {
char cj = chars[j];
if (!set.contains(cj)) {
set.add(cj);
} else {
break;
}
}
if (map.get(c) == null || map.get(c).size() < set.size()) {
map.put(c, set);
}
} for (Map.Entry<Character, Set<Character>> entry : map.entrySet()) {
int lengthTmp = entry.getValue().size();
if (lengthTmp >= length) {
length = lengthTmp;
}
}
return length;
}
2、