classSolution{ public String minWindow(String s, String t){ //滑动窗口 HashMap<Character, Integer> need = new HashMap<>(); HashMap<Character, Integer> window = new HashMap<>(); //统计t中各元素个数 //for(int i =0 ;i<t.length();i++){ // Character key = t.charAt(i); // need.put(key,need.getOrDefault(key,0)+1); //} for(char c : t.toCharArray()){ need.put(c,need.getOrDefault(c,0)+1); } //开始定义窗口双指针 int left =0,right=0; int count = 0;//这个用来记录 int len = Integer.MAX_VALUE; int start = 0; while(right<s.length()){ //获取移入窗口的值 char c = s.charAt(right); right++; //窗口更新 //如果移入的值在所需的字符串中 if(need.containsKey(c)){ //窗口+1 window.put(c,window.getOrDefault(c,0)+1); //如果需要的个数正好满足 if(window.get(c).equals(need.get(c))){ count++; } } //确定左边是否要收缩 while (count==need.size()){