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. 操作MongoDB好用的图形化工具,Robomongo -> 下载 -> 安装

    一 下载 点击下载 -> https://robomongo.org/download 二 安装 直接下一步就行了 -> 择安装位置之后 -> 确认安装

  2. 【大数据】初识Hadoop

    因为项目日志体量较大,每天有4-7T的日志量,传统的sqlserver已经不能满足,所以现在需要使用到大数据的相关工具进行记录和使用. 虽然公共项目提供了组件和解决方案,但是对于一些名词.概念还是有必 ...

  3. Web自动化测试中的接口测试

    1.2.3 接口可测性分析 接口显而易见要比UI简单的都,只需要知道协议和参数即可完成一次请求,从自动化测试实施难易程度来看,有以下几个特征: 1)驱动执行接口的自动化成本不高:HTTP,RPC,SO ...

  4. Linux配置JDK环境

    wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-co ...

  5. java线程基础巩固---Daemon线程的创建以及使用场景分析

    daemon线程既守护线程,而在jdk中对于Thread中针对守护线程有专门的API,如下: 而之前在公司项目中就看到过有人使用过Thread中的这个API,但是对于它的使用场景完全不知,所以这次好好 ...

  6. UICollectionView中的cell 左对齐

    项目中使用UICollectionView做布局,会发现当某个section只有一个cell的时候cell会居中显示,而项目中都是居左显示,这就需要对UICollectionView的布局做些处理,首 ...

  7. 【OI学习注意事项】

    1. 必备知识 普及组必学 1.模拟算法(暴力枚举),按照题目的要求,题目怎么说就怎么做,保证时间和正确性即可. 2.搜索与回溯,主要的是\(DFS\)(深度优先搜索)和\(BFS\)(宽度优先搜索) ...

  8. python wechat

    Python _ithcat持续登陆问题(itchat.auto_login(hotReload=True) https://blog.csdn.net/weixin_43886198/article ...

  9. ubuntu NAT dhcp

    说明: 1.在服务器版本中,没有想桌面版一样的NetworkManager工具,所以的一切都是在命令行上操作的. 2.本文只针对DHCP默认分配的IP进行查看. 方法: 1.如果要使用DHCP,那么需 ...

  10. 函数参数-arguments-reset参数

    1.JS中用:arguments 1)存放实参的集合,是一个类似于数组的对象,只有数组的 length,没有数组方法 function add1(a,b,c) { console.log(argume ...