76. Minimum Window Substring
2021-04-18 23:29
标签:sub tee for 移除 重复元素 logs which 记录 multiple 76. Minimum Window Substring 标签:sub tee for 移除 重复元素 logs which 记录 multiple 原文地址:https://www.cnblogs.com/ranjiewen/p/8683062.html76. Minimum Window Substring
题目
Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n).
For example,
S = "ADOBECODEBANC"
T = "ABC"
Minimum window is "BANC".
Note:
If there is no such window in S that covers all characters in T, return the empty string "".
If there are multiple such windows, you are guaranteed that there will always be only one unique minimum window in S.
解析
// 76. Minimum Window Substring
class Solution_76 {
public:
//1) begin开始指向0, end一直后移,直到begin - end区间包含T中所有字符。记录窗口长度d
//2) 然后begin开始后移移除元素,直到移除的字符是T中的字符则停止,此时T中有一个字符没被包含在窗口,
//3) 继续后移end,直到T中的所有字符被包含在窗口,重新记录最小的窗口d。
//4) 如此循环知道end到S中的最后一个字符。
//时间复杂度为O(n)
string minWindow_(string s, string t) {
string result;
if (s.empty()||s.size()
题目来源
下一篇:记录一次虚拟机安装win7的历程
文章标题:76. Minimum Window Substring
文章链接:http://soscw.com/index.php/essay/76414.html