不含重复字符的最长子串:
代码实现
public int longestSubStr(String str) {
int max = 0;
Deque<Character> deque = new ArrayDeque<>();
for (int i = 0; i < str.length(); i++) {
if (!deque.contains(str.charAt(i))) {
deque.addLast(str.charAt(i));
} else {
max = Math.max(max, deque.size());
while (deque.peek() != str.charAt(i)) {
deque.removeFirst();
}
deque.removeFirst();
deque.addLast(str.charAt(i));
}
}
max = Math.max(max, deque.size());
return max;
}