题解 | #最长无重复子串_滑动窗口
最小覆盖子串
http://www.nowcoder.com/practice/c466d480d20c4c7c9d322d12ca7955ac
@param arr int整型一维数组 the array
@return int整型
#滑动窗口 #1.不断维持滑动窗口内是无重复的,同时继续左移右指针,记录最大长度 #2.如果发现窗口内出现重复,则于东左指针,直到重复消失
#list可以调用sort函数(key,reverse=True)
class Solution:
def maxLength(self , arr ):
# write code here
mm=dict()
left=0
right=0
maxlen=0
length=len(arr)
while right<length:
c=arr[right]
right+=1
if c in mm.keys():
mm[c]+=1
while mm[c]>1:
w=arr[left]
left+=1
mm[w]-=1
else:
mm[c]=1
if len(mm)>maxlen:
maxlen=len(mm)
return maxlen
```