76. Minimum Window Substring

2021-04-09 16:28

阅读:680

标签:==   col   win   ++   ret   ems   string   style   http   

https://leetcode.com/problems/minimum-window-substring/description/

class Solution {
public:
    string minWindow(string s, string t) {
        vectorint> v(256, 0);
        for (auto c : t)
            v[c]++;
        int cnt = t.length();
        int w = 0;
        int minw_start = 0, minw_size = INT_MAX;
        for (int i = 0; i ) {
            if (v[s[i]]-- > 0)  cnt--;
            while (cnt == 0) {
                if (i - w + 1  minw_size) {
                    minw_size = i - w + 1;
                    minw_start = w;
                }
                if (v[s[w]]++ >= 0)     cnt++;
                w++;
            }
        }
        return minw_size == INT_MAX ? "" : s.substr(minw_start, minw_size);
    }
};

 

76. Minimum Window Substring

标签:==   col   win   ++   ret   ems   string   style   http   

原文地址:https://www.cnblogs.com/JTechRoad/p/9060316.html


评论


亲,登录后才可以留言!