Eamsy solution huehue


#1

class Solution:
# @param A : list of integers
# @param B : integer
# @return a list of integers
def dNums(self, A, B):
res=[]
dic={}
for i in range(B):
if A[i] in dic:
dic[A[i]]+=1
else:
dic[A[i]]=1
res.append(len(dic))
for j in range(1,len(A)-B+1):
if dic[A[j-1]]==1:
dic.pop(A[j-1])
else:
dic[A[j-1]]-=1
if A[j+B-1] in dic:
dic[A[j+B-1]]+=1
else:
dic[A[j+B-1]]=1
res.append(len(dic))
return res