java 76. Minimum Window Substring.java

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java 76. Minimum Window Substring.java相关的知识,希望对你有一定的参考价值。

class Solution {
    public String minWindow(String s, String t) {
        if (s == null || s.length() < 1 || t == null || t.length() < 1) return "";
        int end = 0, start = 0, count = t.length();
        int[] vector = new int[256];
        for (char c : t.toCharArray()) {
            vector[c]++;
        }
        char[] str = s.toCharArray();
        String res = "";
        int min = Integer.MAX_VALUE;
        while (end < str.length) {
            if (vector[str[end++]]-- > 0) count--;
            while (count == 0) {
                if (end - start < min) {
                    min = end - start;
                    res = s.substring(start, end);
                }
                if (vector[str[start++]]++ == 0) {
                    count++;
                }
            }
        }
        return res;
    }
}

以上是关于java 76. Minimum Window Substring.java的主要内容,如果未能解决你的问题,请参考以下文章

76. Minimum Window Substring

java 76. Minimum Window Substring.java

java 76. Minimum Window Substring.java

java 76. Minimum Window Substring.java

java 76. Minimum Window Substring.java

java 76. Minimum Window Substring.java