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

遍历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. 《BI那点儿事》SSRS图表和仪表——雷达图分析三国超一流谋士、统帅数据(图文并茂)

    雷达图分析三国超一流谋士.统帅数据,献给广大的三国爱好者们,希望喜欢三国的朋友一起讨论,加深对传奇三国时代的了解 建立数据环境: -- 抽取三国超一流谋士TOP 10数据 DECLARE @t1 TA ...

  2. jquery引用方法时传递参数

    经常到网上去下载大牛们写的js插件.每次只需将js引用并设置下变量就行了,但一直没搞明白原理(主要是大牛们的代码太简练了-,-). 这次弄清了如何传递.设置多个(很多个)参数. 如 方法为functi ...

  3. easyui combotree 只能选择子节点

    //区号只能选子节点 $("#quhao").combotree({ onBeforeSelect: function (node) { //返回树对象 var tree = $( ...

  4. MongoDB:实体对象(javabean)转DBObject

    代码仅供练习(反射,泛型): package utils; import java.lang.reflect.Field; import com.mongodb.BasicDBObject; impo ...

  5. 20169212《Linux内核原理与分析》第三周作业

    最近,深入的阅读了<Linux内核设计与实现>这本书,以下是碰到的一些问题,在此和大家进行交流学习. 碰到的问题 1.为什么不要在linux内核中使用浮点数(这个问题由于书上讲的不够明白, ...

  6. SSM框架学习之高并发秒杀业务--笔记1-- 项目的创建和依赖

    在慕课网上看了Java高并发秒杀API视屏后,觉得这个案例真的让我学到了很多,现在重新自己实现一遍,博客记下,顺便分析其中的要点. 第一步是项目的创建和依赖 利用Maven去创建工程然后导入Idea中 ...

  7. angular directive指令内的参数

    angular.module('myApp', []) .directive('myDirective', function() { return { restrict: String, priori ...

  8. iOS开发UI篇—多控制器和导航控制器简单介绍

    iOS开发UI篇—多控制器和导航控制器简单介绍 一.多控制器 一个iOS的app很少只由一个控制器组成,除非这个app极其简单.当app中有多个控制器的时候,我们就需要对这些控制器进行管理 有多个vi ...

  9. vs2008编译openssl问题

    运行openssl demo 时,debug 版本正常,release 版本报异常:OPENSSL_Uplink(585E6000,08): no OPENSSL_Applink .demo 编译环境 ...

  10. HTML5全局属性和事件

    全局属性和事件能够应用到所有标签元素上,在HTML4中有许多全局属性,比如id,class等.HTML5中又新增了一些特殊功能的全局属性和事件.   属性:   HTML5属性能够赋给标签元素含义和语 ...