public int lengthOfLongestSubstring(String s) {
if (s.length() == 0){
return 0;
}
HashMap<Character,Integer> map = new HashMap<>();
int max = 0;
int left = 0;
for (int i = 0; i < s.length(); i++){
if (map.containsKey(s.charAt(i))){
left = Math.max(left,map.get(s.charAt(i)) + 1);
}
map.put(s.charAt(i),i);
max = Math.max(max,i - left + 1);
}
return max;
}
public List<String> findRepeatedDnaSequences(String s) {
List<String> ans = new ArrayList<>();
int n = s.length();
Map<String, Integer> map = new HashMap<>();
for (int i = 0; i + 10 <= n; i++) {
String cur = s.substring(i, i + 10);
int cnt = map.getOrDefault(cur, 0);
if (cnt == 1) ans.add(cur);
map.put(cur, cnt + 1);
}
return ans;
}
public int minSubArrayLen(int target, int[] nums) {
int left = 0, right = 0;
// 维护窗口内元素之和
int windowSum = 0;
int res = Integer.MAX_VALUE;
while (right < nums.length) {
// 扩大窗口
windowSum += nums[right];
right++;
while (windowSum >= target && left < right) {
// 已经达到 target,缩小窗口,同时更新答案
res = Math.min(res, right - left);
windowSum -= nums[left];
left++;