我的超时思路,感觉自己上了一个新的台阶,虽然超时了,但起码是给出了一个方法。

遍历s 一遍即可,两个指针,当找到了一个合格的字串后,start 开始走,直到遇到s[start]在t中

如果不符合,end++,直到遇到s[end]在t中。

class Solution {
public:

string minWindow(string s, string t) {
int start=0,end=t.size()-1;
string res;
int len=INT_MAX;
map<char,int> coll;
for(int i=0;i<t.size();i++)
{
coll[t[i]]++;
}
while(end<s.size())
{
string str=s.substr(start,end-start+1);
if(check(str,t))
{
if(end-start+1 < len)
{
len=end-start+1;
res=str;
}
while(++start < end && coll[s[start]] == 0);
}
else while(++end<s.size() && coll[s[end]] == 0);
}
return res;
}
bool check(string str,string t)
{
map<char,int> coll;
for(int i=0;i<str.size();i++)
{
coll[str[i]]++;
}
for(i=0;i<t.size();++i)
{
if(coll[t[i]]==0)
return false;
else
coll[t[i]]--;
}
return true;
}
};

  看了几个别人的,越发觉得我这个思路很清晰,可惜超时,先这样吧。

转载于:https://www.cnblogs.com/yanqi110/p/4997776.html

LeetCode()Minimum Window Substring 超时,但觉得很清晰。相关推荐

  1. LeetCode - Minimum Window Substring

    题目: Given a string S and a string T, find the minimum window in S which will contain all the charact ...

  2. [LeetCode] Minimum Window Substring 散列映射问题

    题目: Given a string S and a string T, find the minimum window in S which will contain all the charact ...

  3. Minimum Window Substring @LeetCode

    不好做的一道题,发现String Algorithm可以出很多很难的题,特别是多指针,DP,数学推导的题.参考了许多资料: http://leetcode.com/2010/11/finding-mi ...

  4. 【打印代码+好好理解+子串问题】LeetCode 76. Minimum Window Substring

    LeetCode 76. Minimum Window Substring 字符串子串问题!!!理解这题真是花了很大的功夫!!! 参考链接:https://blog.csdn.net/weixin_4 ...

  5. LeetCode 76. Minimum Window Substring / 567. Permutation in String

    76. Minimum Window Substring 典型Sliding Window的问题,维护一个区间,当区间满足要求则进行比较选择较小的字串,重新修改start位置. 思路虽然不难,但是如何 ...

  6. LeetCode 笔记系列16.3 Minimum Window Substring [从O(N*M), O(NlogM)到O(N),人生就是一场不停的战斗]...

    题目:Given a string S and a string T, find the minimum window in S which will contain all the characte ...

  7. LeetCode 笔记系列16.1 Minimum Window Substring [从O(N*M), O(NlogM)到O(N),人生就是一场不停的战斗]...

    题目: Given a string S and a string T, find the minimum window in S which will contain all the charact ...

  8. LeetCode 笔记系列16.2 Minimum Window Substring [从O(N*M), O(NlogM)到O(N),人生就是一场不停的战斗]...

    题目:Given a string S and a string T, find the minimum window in S which will contain all the characte ...

  9. 72.Minimum Window Substring(最小子串窗口)

    Level:   Hard 题目描述: Given a string S and a string T, find the minimum window in S which will contain ...

  10. Minimum Window Substring 最小覆盖子串算法

    转载:https://blog.csdn.net/fly_yr/article/details/51134340 题目 最小子串覆盖 给定一个字符串source和一个目标字符串target,在字符串s ...

最新文章

  1. 如何处理日志文件丢失
  2. 12.委托是什么?委托的property声明用什么属性?为什么?
  3. Deep Learning源代码收集-持续更新…
  4. 软考-信息系统项目管理师-项目组合管理
  5. 2013_warmup
  6. android fragment addtobackstack,Android Fragment Back Stack的问题
  7. L2TP连接尝试失败,因为安全层在初始化与远程计算机的协商时遇到一个处理错误...
  8. c语言自动计费工作,c语言编程实现话单计费实例
  9. Java中的this有哪四种用法
  10. c语言编程学习入门指南
  11. 百万级别数据库优化方案
  12. MySQL实战系列3:视图、存储过程、函数、索引全解析
  13. 【C++刷LeetCode套路1】Array题型: 双指针Two Pointers套路
  14. vant 中 van-address-edit地址编辑 地址回显获取 areaCode
  15. html+视频添加字幕,给视频加滚动字幕,给视频加字幕制作mv 录制的视频配背景音乐...
  16. 源码安装postgresql9.5.1
  17. 推荐5个免费的字体转换网站工具
  18. Clamav 杀毒软件安装
  19. 2022年《国家职业教育智慧平台应用推广培训》课程-答案--(中职)已验证
  20. 土木专业的SCI 期刊

热门文章

  1. 优化器——梯度下降优化算法综述
  2. EMNLPICLR 多模态学习前沿分享
  3. 【NLP】目前有比Topic Model更先进的聚类方式么?比如针对短文本的、加入情感分析的?...
  4. [TACL18]隐式句法树模型真的能学到句子中有意义的结构吗?
  5. NLP—1.自然语言处理的基础任务与应用
  6. 机器学习基础算法12-回归实例-广告预测
  7. Mysql/Mariadb本地不可以登录,远程可以登录问题的解决
  8. 60 秒 Linux 检查清单,快速初步定位你的性能问题
  9. 如何维护应用程序状态
  10. 有趣的算法(一):如何让有情人终成眷属