leetcode-hard-array-76. Minimum Window Substring -NO
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的更多相关文章
- 刷题76. Minimum Window Substring
一.题目说明 题目76. Minimum Window Substring,求字符串S中最小连续字符串,包括字符串T中的所有字符,复杂度要求是O(n).难度是Hard! 二.我的解答 先说我的思路: ...
- 【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 ...
- [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 ...
- [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 ...
- 【一天一道LeetCode】#76. Minimum Window Substring
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given a ...
- [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 ...
- 【LeetCode】76. Minimum Window Substring 最小覆盖子串(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 滑动窗口 日期 题目地址: https://leet ...
- 76. Minimum Window Substring
题目: Given a string S and a string T, find the minimum window in S which will contain all the charact ...
- 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 ...
- 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 ...
随机推荐
- 数据集:Introduction to Econometrics by Stock&Watson
James H. Stock and Mark W. Watson, Introduction to Econometrics: data sets 詹姆斯·H·斯托克 马克·W·沃森. 计量经济学. ...
- 【Java】 BIO与NIO以及AIO分析
一.BIO与NIO以及AIO的概念 BIO是同步阻塞式的IO NIO是同步非阻塞的IO (NIO1.0,JDK1.4) AIO是非同步非阻塞的IO(NIO2.0,JDK1.7) 二.BIO简单分析 1 ...
- 高性能SQLServer分页语句
第一种方法:效率最高 SELECT TOP 页大小 * FROM( SELECT ROW_NUMBER() OVER (ORDER BY id) AS RowNumber,* FROM table1 ...
- odoo 关系字段(关联关系)
Many-to-one关联 publisher_id = fields.Many2one(comodel_name= 'res.partner', domain='',context={},ondel ...
- 《python解释器源码剖析》第10章--python虚拟机中的一般表达式
10.0 序 上一章中,我们通过PyEval_EvalFrameEx看到了python虚拟机的整体框架,那么这一章我们将深入到PyEval_EvalFrameEx的各个细节当中,深入剖析python的 ...
- 7.JVM技术_java监控工具使用
1.java监控工具使用 2.jconsole jconsole是一种集成了上面所有命令功能的可视化工具,可以分析jvm的内存使用情况和线程等信息 2.1.启动jconsole 通过JDK/bin目录 ...
- The basic concept of information theory.
Deep Learning中会接触到的关于Info Theory的一些基本概念.
- zencart批量评论插件Easy Populate CSV add reviews使用教程
此插件在Easy Populate CSV 1.2.5.7b产品批量插件基础上开发,有1.3x与1.5x两个版本. zencart批量评论插件Easy Populate CSV add reviews ...
- openssh的服务端配置文件
一.因为部分配置长时间不使用就忘了,为了方便查阅,我在这里检点写一些比较有用的ssh配置选项. PortListenAddress ip #监听自己的哪个端口,默认是都监听的,如果指定了I ...
- WPF界面开发技巧大放送!DevExpress WPF在TreeListView中扩展N级
DevExpress广泛应用于ECM企业内容管理. 成本管控.进程监督.生产调度,在企业/政务信息化管理中占据一席重要之地.通过DevExpress WPF Controls,您能创建有着强大互动功能 ...