fork download
  1. def minWindow(s: str, t: str) -> str:
  2. s_hashmap = {}
  3. t_hashmap = {}
  4. left, right = 0, 0
  5. min_substring = ' ' * 1001
  6. if len(s) < len(t):
  7. return ''
  8. for c in t:
  9. if c not in t_hashmap:
  10. t_hashmap[c] = 1
  11. else:
  12. t_hashmap[c] += 1
  13.  
  14. while right < len(s):
  15. if s[right] in t_hashmap:
  16. if s[right] not in s_hashmap:
  17. s_hashmap[s[right]] = 1
  18. else:
  19. s_hashmap[s[right]] += 1
  20.  
  21. if s_hashmap == t_hashmap:
  22. if (right - left + 1) < len(min_substring):
  23. min_substring = s[left:right+1]
  24. s_hashmap.clear()
  25. left = right = left + 1
  26. else:
  27. right += 1
  28.  
  29. return min_substring
  30.  
  31. print(minWindow("ADOBECODEBANC", "ABC"))# your code goes here
Success #stdin #stdout 0.07s 14080KB
stdin
Standard input is empty
stdout
ADOBEC