class Solution:
def minWindow(self, s: str, t: str) -> str:
n = len(s)
if n==0:
return ""
if len(t)==0:
return s
#if s == t:
# return s
dic = {}
dic2= {}
for i in range(len(t)):
dic.update({t[i]:0})
if t[i] in dic2.keys():
dic2.update({t[i]:dic2[t[i]]+1})
else:
dic2.update({t[i]:1})
#dicount = len(t)
i = 0
j = 0
minstr = ""
minwidth = n
while i <=j and j<n :
#j++
if s[j] in t:
dic.update({s[j]:dic[s[j]]+1})
valid = True
for k in dic.keys():
if dic[k]<dic2[k]:
valid = False
break
if valid:
#valid
curlen = j-i+1
if curlen<=minwidth:
minwidth = curlen
minstr = s[i:j+1]
#i++
while i<=j:
if s[i] not in dic.keys():
i += 1
else:
if dic[s[i]]>dic2[s[i]]:
dic.update({s[i]:dic[s[i]]-1})
i += 1
else:
curlen = j-i+1
if curlen <= minwidth:
minwidth = curlen
minstr = s[i:j+1]
break
#else:
#invalid j += 1 return minstr

leetcode76的更多相关文章

  1. leetcode76. Minimum Window Substring

    leetcode76. Minimum Window Substring 题意: 给定字符串S和字符串T,找到S中的最小窗口,其中将包含复杂度O(n)中T中的所有字符. 例如, S ="AD ...

  2. 【leetcode76】Intersection of Two Arrays II

    题目描述: 给定两个数组求他们的公共部分,输出形式是数组,相同的元素累计计数 例如: nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2]. 原文描述: G ...

  3. [Swift]LeetCode76. 最小覆盖子串 | Minimum Window Substring

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

  4. 【1】【leetcode-76】 最小覆盖子串

     最小覆盖子串(hard) (不会) 给定一个字符串 S 和一个字符串 T,请在 S 中找出包含 T 所有字母的最小子串. 示例: 输入: S = "ADOBECODEBANC", ...

  5. tusen 刷题

    //1.single number和变体 //2.lru lfu 3.给一个正整数集合,求一个和最大且能被3整除的子集.Follow up: 如果集合里有正有负 4.leetcode200-numbe ...

  6. LeetCode practice

    子集和问题:给定一组数和一个值,从这组数中选出若干个数使其和为给定的值.这是个NPC问题. 1.https://leetcode.com/problems/counting-bits/#/soluti ...

随机推荐

  1. UVALive - 4223,hdu2962(简单dijkstra)

    Trucking Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  2. fiddler之数据统计(statistics)

    在使用fiddler代理监听访问时,可以使用statistics分页去统计请求和响应的一些信息. 界面显示如下: 可以在这里查看一个session的统计信息 说明: 1.request count:请 ...

  3. vue导出excel

    1.按装依赖 cnpm install -S file-saver xlsx cnpm install -D script-loader 2.引入Blob.js和expor2Excal.js 3.在m ...

  4. Curl追踪请求延时问题

    背景原因:测试环境发现一个连接内网访问和外网访问延迟差别很大,内网访问很快.外网访问很慢.于是我们用curl来诊断问题所在的区域! 命令如下: curl -o /dev/null -s -w %{ti ...

  5. Open Nginx gzip

    默认情况下,Nginx的gzip压缩是关闭的, gzip压缩功能就是可以让你节省不少带宽,但是会增加服务器CPU的开销哦,Nginx默认只对text/html进行压缩 ,如果要对html之外的内容进行 ...

  6. 软件工程 week 02

    一.地址链接 1.作业地址:https://edu.cnblogs.com/campus/nenu/2016CS/homework/2110 2.git仓库地址:https://git.coding. ...

  7. spring boot 1.4 整合 mybatis druid

    http://www.jianshu.com/p/cef49ad91ba9spring boot 1.4 整合 mybatis druid

  8. I think I need a boat house

    I think I need a boat house. Fred Mapper is considering purchasing some land in Louisiana to build h ...

  9. PHP处理上传文件信息数组中的文件类型 正确获取

    PHP处理上传文件信息数组中的文件类型$_FILES['type']由客户端浏览器提供,有可能是黑客伪造的信息,请写一个函数来确保用户上传的图像文件类型真实可靠 如果是一般文件则通过 mime_con ...

  10. Java BigInterger类

    BigInteger概述 可以让超过Integer范围内的数据进行运算 构造方法 public BigInteger(String val) 成员方法 public BigInteger add(Bi ...