76. Minimum Window Substring
2021-04-09 16:28
标签:== col win ++ ret ems string style http https://leetcode.com/problems/minimum-window-substring/description/ 76. Minimum Window Substring 标签:== col win ++ ret ems string style http 原文地址:https://www.cnblogs.com/JTechRoad/p/9060316.htmlclass 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
文章链接:http://soscw.com/index.php/essay/73402.html