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

遍历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. jquery mobile 和phonegap开发总结之三跨域加载页面

    跨域加载 一要进行一定的配置见下面 $( document ).bind( "mobileinit", function() { // Make your jQuery Mobil ...

  2. linux 知识汇总

    1 ) linux下文件系统类型的学习 2 )深入理解linux i节点(inode) 3 )RAID系列

  3. Deep Learning 10_深度学习UFLDL教程:Convolution and Pooling_exercise(斯坦福大学深度学习教程)

    前言 理论知识:UFLDL教程和http://www.cnblogs.com/tornadomeet/archive/2013/04/09/3009830.html 实验环境:win7, matlab ...

  4. 主成分分析(PCA)核心思想

    参考链接:http://pinkyjie.com/2011/02/24/covariance-pca/ PCA的本质其实就是对角化协方差矩阵. PCA就是将高维的数据通过线性变换投影到低维空间上去,但 ...

  5. javascript数组常用方法汇总

    1.join()方法: Array.join()方法将数组中所以元素都转化为字符串链接在一起,返回最后生成的字符串.也可以指定可选的字符串在生成的字符串中来分隔数组的各个元素.如果不指定分隔符,默认使 ...

  6. Chinese culture

      文房四宝 笔墨纸砚是中国古代文人书房中必备的宝贝,被称为“文房四宝”.用笔墨书写绘画在 中国可追溯到五千年前.秦(前221---前206)时已用不同硬度的毛和竹管制笔:汉代(前206—公元220) ...

  7. js高级程序设计(七)函数表达式

    定义函数的方式有两种:一种是函数声明,另一种就是函数表达式.函数声明的语法是这样的. function functionName(arg0, arg1, arg2) { //函数体 } Firefox ...

  8. HR函数学习02——分配组织单位

    REPORT ZLYHR01. "创建组织单元 成功 DATA:LS_OBJ TYPE OBJEC, LV_STU TYPE GDSTR-SVECT, LV_TIT TYPE CHAR20, ...

  9. 字符串与模式匹配(一)——KMP算法

    源码:kmp.cpp // KMP.cpp : Defines the entry point for the console application. // #include "stdaf ...

  10. junit基础篇、中级篇-实例代码

    学习文章: http://blog.csdn.net/andycpp/article/details/1327147 http://wenku.baidu.com/link?url=C27gDEj0l ...