fork download
  1. # your code goes here
  2.  
  3.  
  4. def length_of_substr(s: str) ->int:
  5. last_seen = {}
  6. left = 0
  7. max_length = 0
  8.  
  9. for right, char in enumerate(s):
  10. if char in last_seen and last_seen[char] >= left:
  11. left = last_seen[char] + 1
  12.  
  13. last_seen[char] = right
  14. max_length = max(max_length, right - left +1)
  15.  
  16. return max_length
  17.  
  18. s = "abcdabcbbxyzt"
  19. print(length_of_substr(s))
Success #stdin #stdout 0.07s 14044KB
stdin
Standard input is empty
stdout
5