题目
思路参考《算法小抄》
class Solution {public String minWindow(String s, String t) {int startIndex = -1, endIndex = s.length(), valid = 0, left = 0, right = 0;char[] sArray = s.toCharArray();char[] tArray = t.toCharArray();int[] need = new int[256];int[] window = new int[256];Set<Character> set = new HashSet<>();for (char c : tArray) {set.add(c);++need[c];}while (right < sArray.length) {char c = sArray[right];++right;if (!set.contains(c)) {continue;}++window[c];if (window[c] == need[c]) {++valid;}while (valid == set.size() && left < right) {if (right - left < endIndex - startIndex) {startIndex = left;endIndex = right;}char d = sArray[left];++left;if (!set.contains(d)) {continue;} else {if (window[d] == need[d]) {--valid;}--window[d];}}}return startIndex == -1 ? "" : s.substring(startIndex, endIndex);}
}