一 : 最长不含重复字符的子字符串
方法 : 滑动窗口法
import java.util.*;
public class Solution {
/**
*
* @param s string字符串
* @return int整型
*/
public int lengthOfLongestSubstring (String s) {
// write code here
int left = 0;
int right = 0;
int length = 0;
int maxLength = 0;
HashSet<Character> set = new HashSet<>();
while(right < s.length()) {
char cur = s.charAt(right);
if(!set.contains(cur)) {
set.add(cur);
length++;
if(length > maxLength) {
maxLength = length;
}
right++;
} else {
set.remove(s.charAt(left));
left++;
length--;
while(set.contains(cur)) {
set.remove(s.charAt(left));
left++;
length--;
}
}
}
return maxLength;
}
}