我想找到只有一个输入的最小窗口。我坚持要删除字符串中的重复字母。
def window(string):
"""
>>> window('The quick brown fox jumps over the lazy dog.')
'quick brown fox jumps over the lazy dog'
"""
count1={}
for char in string.lower():
if char.isalpha():
if char not in count1:
count1[char]=1
else:
count1[char]+=1
c=26
print(count1) #print how many alphabet exists in string(checking).
alphabet='abcdefghijklmnopqrstuvwxyz'
start=0
minstart=0
end = 0
for end in range(0, len(alphabet)):
if alphabet[end] in count1:
if count1[alphabet[end]]>0:
count1[alphabet[end]]-=1
if count1[alphabet[end].lower()]>=0:
c-=1
print(count1)#print count1 that deleted alphabet(26) once.
if c==0:
while True:#run while loop for 9 times
for start in range(0, len(string)):
if string[start].lower() in count1:
if count1[string[start].lower()]>0:
minstart+=1
count1[alphabet[end]]-=1
在if c==0:
行,我尝试从count1
删除一次字母,这使得字母在count1
中几乎变为零,并且仍为o:3,e:2,r:1,h:1,u:1,t:1
。
我尝试删除t
,h
,e
并找到最小窗口开始位置(minstart += 1
),但我不确定此代码。