Advertisement
malixds_

Untitled

Jun 16th, 2023
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. class Solution:
  2. def lengthOfLongestSubstring(self, s: str) -> int:
  3. if len(s) == 0:
  4. return 0
  5. result = 1
  6. length_str = len(s)
  7. s = list(s)
  8. a = 0
  9. while True:
  10. a += 1
  11. if len(s) != length_str:
  12. length_str = len(s)
  13. a = 1
  14. if a == len(s) or result == 95:
  15. return result
  16. tmp = 1
  17. for k in range(0, a):
  18. if len(s) == 1:
  19. return result if result > 1 else 1
  20. if s[k] == s[a]:
  21. s = s[k+1:]
  22. break
  23. else:
  24. tmp += 1
  25. if tmp > result:
  26. result = tmp
  27.  
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement