mycode

不会。。

参考:

class Solution(object):
def minWindow(self, s, t):
"""
:type s: str
:type t: str
:rtype: str
"""
count1 = collections.defaultdict(int)
count2 = []
for char in t:
count1[char] += 1
count2.append(char) count = len(t)
start = 0
minSize = len(s) + 1
minStart = 0 for end in range(len(s)):
if s[end] in count2 :
#print(end,count1,count2,count)
count1[s[end]] -= 1
if count1[s[end]] >= 0: #<=0时表示出现了多余的t中要求的元素,比如t中两个A,现在出现了第三个A,所以没必要count-1
count -= 1
if count == 0:
while True:
if s[start] in count2 :
if count1[s[start]] < 0: #s中第一个出现t中元素的位置可以被更换啦
count1[s[start]] += 1
else: #
print(start)
break
start += 1
if minSize > end - start + 1:
minSize = end - start + 1
minStart = start
#print(end,count1,count2,count) if minSize < len(s) + 1:
return s[minStart:minStart + minSize]
else:
return '' class Solution(object):
def minWindow(self, s, t):
"""
:type s: str
:type t: str
:rtype: str
"""
count1 = collections.defaultdict(int)
count2 = []
for char in t:
count1[char] += 1
count2.append(char) count = len(t)
start = 0
minSize = len(s) + 1
minStart = 0 for end in range(len(s)):
if s[end] in count2 :
#print(end,count1,count2,count)
count1[s[end]] -= 1
if count1[s[end]] >= 0:
count -= 1
if count == 0:
while True: if s[start] in count2 :
if count1[s[start]] < 0:
count1[s[start]] += 1
else:
print(start)
break
start += 1
if minSize > end - start + 1:
minSize = end - start + 1
minStart = start
#print(end,count1,count2,count) if minSize < len(s) + 1:
return s[minStart:minStart + minSize]
else:
return ''

leetcode-hard-array-76. Minimum Window Substring -NO的更多相关文章

  1. 刷题76. Minimum Window Substring

    一.题目说明 题目76. Minimum Window Substring,求字符串S中最小连续字符串,包括字符串T中的所有字符,复杂度要求是O(n).难度是Hard! 二.我的解答 先说我的思路: ...

  2. 【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 ...

  3. [LeetCode] 76. Minimum Window Substring 最小窗口子串

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

  4. [LeetCode] 76. 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】#76. Minimum Window Substring

    一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given a ...

  6. [leetcode]76. Minimum Window Substring最小字符串窗口

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

  7. 【LeetCode】76. Minimum Window Substring 最小覆盖子串(Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 滑动窗口 日期 题目地址: https://leet ...

  8. 76. Minimum Window Substring

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

  9. 76. Minimum Window Substring(hard 双指针)

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

  10. 76. Minimum Window Substring (JAVA)

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

随机推荐

  1. 转载Linux常用命令

    转自:https://blog.csdn.net/deng_xj/article/details/88803148 Linux常用shell命令 [root@dengxj]#各项含义[用户名@计算机名 ...

  2. http://www.moext.com博客搬家到这里啦

    1.原博客莫叉特用的是自己的域名http://www.moext.com,由于服务器在国外,访问不太稳定,SEO做得也很不好: 2.喜欢博客园的极简风格,目前来看广告量也在可接受范围: 3.一个偶然的 ...

  3. MySQL的基本操作一

    本文主要涉及到的SQL知识点包括CREATE创建数据库和表.INSERT插入数据.SUM()求和.GROUP BY分组.DATE_FORMAT()格式化日期.ORDER BY排序.COUNT()统计行 ...

  4. 安装openblas库

    http://www.openblas.net/ Linux:下载源码直接make即可

  5. SYSLINUX官方文档

    帮助正确认识SYSLINUX http://www.syslinux.org/wiki/index.php/Doc/syslinux http://www.syslinux.org/wiki/inde ...

  6. makefile学习之函数

    GNU make支持内置函数以及用户自定义函数,下面结合例子简单介绍一下. gnu make版本: 4.1 一.用户自定义函数 格式: $(call macro-name{, param1 ···}) ...

  7. Bootstrap常用的自带插件

    Bootstrap自带的那些常用插件. 模态框 模态框的HTML代码放置的位置 务必将模态框的HTML代码放在文档的最高层级内(也就是说,尽量作为 body 标签的直接子元素),以避免其他组件影响模态 ...

  8. ubantu32位 linux下hexedit的下载安装

    Hexedit软件介绍: hexedit是一个开源的完全免费的命令行软件,可用于在任何GNU / Linux操作系统下以十六进制和ASCII(美国信息交换标准代码)格式查看和编辑文件. 下载: 在so ...

  9. MySQL in和limit不能连用的问题

    今天在mysql上处理一个数据量达到千万级的数据库表时,要取出满足条件的数据集,然后存入到mongo数据库,使用JPA提供的Pageble去拿分页,再用多线程去取数据时,发现刚开始效率还可以,肯定比单 ...

  10. git撤销pull命令

    1.运行git reflog命令查看你的历史变更记录 2.然后用git reset --hard HEAD@{n},(n是你要回退到的引用位置)回退. 比如上图可运行 git reset --hard ...