Recommend a cross-platform open source free file transfer artifact LANDrop, realize computer mobile phone transfer, unlimited speed! Support Windows, Android, iOS, macOS, ipad and other full platforms
The address is as follows: LANDrop - Drop any files to any devices on your LAN
If you are transferring between an Android phone and a Windows computer, download and install the Android and Windows versions
Open the executable program, drag the file in the pop-up window and transfer it. The computer will automatically identify the IP and port of the mobile phone. Note that the computer and the mobile phone must be in the same wifi or LAN
public class SlideWindow {
public static void main(String[] args) {
SlideWindow a = new SlideWindow();
System.out.println(a.minWindow("ADOBECODEBANC", "ABC"));
}
public String minWindow(String s, String t) {
String res = "";
if (t.length() > s.length()) {
return res;
}
HashMap<Character, Integer> need = new HashMap<>();
HashMap<Character, Integer> window = new HashMap<>();
for (int i = 0; i < t.length(); i++) {
char ch = t.charAt(i);
need.put(ch, need.getOrDefault(ch, 0) + 1);
}
// 定义字符串左右指针
int left = 0;
int right = 0;
// valid 变量表示窗口中满足 need 条件的字符个数
int valid = 0;
// 定义符合字符串的起始索引
int len = Integer.MAX_VALUE;
int start = 0;
while (right < s.length()) {
char ch = s.charAt(right);
right++;
if (need.containsKey(ch)) {
window.put(ch, window.getOrDefault(ch, 0) + 1);
if (window.get(ch).equals(need.get(ch))) {
valid++; // valid 加一次,说明窗口里面某一个字符又符合了
}
}
// 如果 valid 和 need.size 的大小相同,则说明窗口已满足条件
// 判断左侧窗口是否要收缩
while (valid == need.size()) {
// 在这里更新最小覆盖子串
if (right - left < len) {
start = left;
len = right - left;
}
// d 是将移出窗口的字符
char d = s.charAt(left);
// 左移窗口
left++;
// 进行窗口内数据的一系列更新
if (need.containsKey(d)) {
if (window.get(d).equals(need.get(d))) {
valid--;
}
window.put(d, window.get(d) - 1);
}
}
}
return len == Integer.MAX_VALUE ? "" : s.substring(start, start + len);
}
}