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 ...
随机推荐
- Matplotlib 随机漫步图
import matplotlib.pyplot as plt from random import choice class Randomwalk(): def __init__(self,num_ ...
- python网络编程:TCP通讯模板、粘包及解决方案、自定义报头
一.TCP通讯模板 二.远程CMD程序 三.解决粘包问题 四.解决粘包问题2 一.TCP通讯模板 TCP客户端 import socket c = socket.socket() # 连接服务器 c. ...
- ListView 一维排布 动态滑动添加新item代码
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentV ...
- Windows bat脚本的for语句
Windows bat脚本的for语句基本形态如下: 在cmd窗口中:for %I in (command1) do command2 在批处理文件中:for %%I in (command1) do ...
- 1.opencv_画图
#导入工具包 import numpy as np import cv2 import matplotlib.pyplot as plt # 定义显示图片 def show(image): plt.i ...
- 【墨西哥区域赛】Carpet
原题: 题意: 给你一个树,有1e5个节点,让你把这个树放在一个长1e6宽20的网格图里,要求一个格子放一个节点,树边之间不能相交 这是一道构造题 因为树的形状可能性很多,很复杂,所以不能简单猜测,而 ...
- golang高并发
golang 为什么能做到高并发 goroutine是go并行的关键,goroutine说到底就是携程,但是他比线程更小,几十个goroutine可能体现在底层就是五六个线程,Go语言内部帮你实现了这 ...
- wget 小技巧
一,案例 wget, 一个强大的下载命令.下载文件如果由于中途因本地网络问题断开了,没下载完,重新运行了一下WGET命令,会发现完全在重新下载了,新文件名字会在后面加个1..... 这是wget下载失 ...
- stm32 cubemx hal dma uart参考例程,发送和接收
参考:https://blog.csdn.net/toopoo/article/details/80012317https://blog.csdn.net/morixinguan/article/de ...
- 【agc005d】~K Perm Counting
题目大意 求有多少中1~n的排列,使得\(abs(第i个位置的值-i)!=k\) 解题思路 考虑容斥,\(ans=\sum_{i=0}^{n}(-1)^ig[i](n-i)!(g[i]表示至少有i个位 ...