76. Minimum Window Substring
Posted The Tech Road
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了76. Minimum Window Substring相关的知识,希望对你有一定的参考价值。
https://leetcode.com/problems/minimum-window-substring/description/
class Solution { public: string minWindow(string s, string t) { vector<int> 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 < s.length(); 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的主要内容,如果未能解决你的问题,请参考以下文章
算法第76题 Minimum Window Substring
java 76. Minimum Window Substring.java