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

遍历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;
}
};

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

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 characters ...

  2. [leetcode]Minimum Window Substring @ Python

    原题地址:https://oj.leetcode.com/problems/minimum-window-substring/ 题意: Given a string S and a string T, ...

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

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

  4. Leetcode Minimum Window Substring

    Given a string S and a string T, find the minimum window in S which will contain all the characters ...

  5. [Leetcode] minimum window substring 最小字符窗口

    Given a string S and a string T, find the minimum window in S which will contain all the characters ...

  6. Minimum Window Substring @LeetCode

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

  7. LeetCode解题报告—— Minimum Window Substring && Largest Rectangle in Histogram

    1. Minimum Window Substring Given a string S and a string T, find the minimum window in S which will ...

  8. 【LeetCode】76. Minimum Window Substring

    Minimum Window Substring Given a string S and a string T, find the minimum window in S which will co ...

  9. 53. Minimum Window Substring

    Minimum Window Substring Given a string S and a string T, find the minimum window in S which will co ...

随机推荐

  1. HDU-4532 湫秋系列故事——安排座位 组合数学DP

    题意:有来自n个专业的学生,每个专业分别有ai个同学,现在要将这些学生排成一行,使得相邻的两个学生来自不同的专业,问有多少种不同的安排方案. 分析:首先将所有专业的学生视作一样的,最后再乘以各自学生的 ...

  2. iOS - Git 代码版本管理

    1.Git Git 是用 C 语言开发的分布版本控制系统.版本控制系统可以保留一个文件集合的历史记录,并能回滚文件集合到另一个状态(历史记录状态).另一个状态可以是不同的文件,也可以是不同的文件内容. ...

  3. 15 sql base line 工作机制

    <个人Configuration> 正常配置一下, 就OK了, 不用理了, oracle 11g 默认启动 发展: .从Oracle的发展角度来看,估计这种方法是Oracle发展和改进的方 ...

  4. java高薪之路__007_反射

    参考地址: 1. http://www.cnblogs.com/rollenholt/archive/2011/09/02/2163758.html2. http://www.cnblogs.com/ ...

  5. 最精简的django程序

    一.程序框架 1.结构图

  6. Linux平台下快速搭建FTP服务器

      FTP 是File Transfer Protocol(文件传输协议)的英文简称,而中文简称为"文传协议".用于Internet上的控制文件的双向传输.同时,它也是一个应用程序 ...

  7. Windows7系统下JAVA运行环境下载、安装和设置(第二次更新:2012年03月14日)

    1.下载 地址:http://www.oracle.com/technetwork/java/javase/downloads/index.html,(由于Sun于2009年被oracle收购所以网址 ...

  8. Spring相关:jdom学习:读取xml文件

    云课堂马士兵的spring2.5课程中提到的 用JDOM读取XML文件需先用org.jdom.input.SAXBuilder对象的build()方法创建Document对象,然后用Document类 ...

  9. 源代码tfs to git

    TFSàgit可以保留完整历史记录,方法: https://github.com/git-tfs/git-tfs 系统变量的path里加上: ;C:\Program Files (x86)\Git\b ...

  10. 转: javascript实现全国城市三级联动菜单代码

    <html> <head> <title>js全国城市三级联动菜单代码_B5教程网</title> <meta http-equiv=" ...