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 ...
随机推荐
- shell中$(( ))、$( )、``与${ }的区别详解
命令替换在bash中,$( )与` `(反引号)都是用来作命令替换的.命令替换与变量替换差不多,都是用来重组命令行的,先完成引号里的命令行,然后将其结果替换出来,再重组成新的命令行 [python@m ...
- JDBC概述及JDBC完成对Oracle的增删改查
什么是JDBC JDBC(Java Data Base Connectivity,Java数据库连接),是一种用于执行SQL语句的Java API,为多种关系数据库提供统一访问.它由一组用Java语言 ...
- 【C/C++】内存对齐规则和实战
内存对齐规则和实战 这篇文章是我的平时的一个笔记修改后来的.这里主要介绍一下内存对齐的规则,以及提供一些实战一下.几篇我觉得比较好的详细的介绍内存对齐的作用什么的博文会在文末附上. 规则 在开始实战前 ...
- 2.java多线程_synchronized(Lock)同步
1.synchronized同步关键词 线程安全是并发编程中的重要关注点,应该注意到的是,造成线程安全问题的主要诱因有两点,一是存在共享数据(也称临界资源),二是存在多条线程共同 操作共享数据.因此为 ...
- python读取txt文件时报错UnicodeDecodeError: 'gbk' codec can't decode byte 0x8e in position 8: illegal multibyte sequence
python读取文件时报错UnicodeDecodeError: 'gbk' codec can't decode byte 0x8e in position 8: illegal multibyte ...
- Mike and Feet CodeForces - 548D (单调栈)
Mike is the president of country What-The-Fatherland. There are n bears living in this country besid ...
- JS 获取和返填单选按钮Value值
1.获取Radio值 $('input[name="sex"]:checked ').val(); 2.返填Radio值 $('input[name="sex" ...
- 微软Blazor组件发布,DevExpress v19.1.8中可用:Charts新功能
点击获取DevExpress v19.2.3最新完整版试用下载 DevExpress UI for Blazor在v19.1.8中可用,此次更新发布包括DevExpress Blazor组件的主要功能 ...
- 喜大普奔!.NET界面控件DevExpress v19.2发布,快来下载体验
DevExpress Universal Subscription(又名DevExpress宇宙版或DXperience Universal Suite)是全球使用广泛的.NET用户界面控件套包,De ...
- PHP Swoole websocket协议实现