Advertisement
Iam_Sandeep

Smallest distinct window

Aug 6th, 2022
986
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.49 KB | None | 0 0
  1. class Solution:
  2.     def findSubString(self, s):
  3.         v=set(s)
  4.         l=0
  5.         d={}
  6.         need=len(v)
  7.         n=len(s)
  8.         ans=n+1
  9.         have=0
  10.         for r,rc in enumerate(s):
  11.             d[rc]=d.get(rc,0)+1
  12.             if d[rc]==1:have+=1
  13.             while have==need:
  14.                 ans=min(ans,r-l+1)
  15.                 d[s[l]]-=1
  16.                 if d[s[l]]==0:
  17.                     d.pop(s[l])
  18.                     have-=1
  19.                 l+=1
  20.         return ans
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement