Advertisement
serega1112

3

Dec 13th, 2020
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.42 KB | None | 0 0
  1. class Solution:
  2.     def lengthOfLongestSubstring(self, s: str) -> int:
  3.  
  4.         l = 0
  5.         r = 0
  6.         memo = set()
  7.         res = 0
  8.        
  9.         while r < len(s):
  10.             if s[r] not in memo:
  11.                 memo.add(s[r])
  12.                 r += 1
  13.                 res = max(res, r - l)
  14.             else:
  15.                 memo.remove(s[l])
  16.                 l += 1
  17.                
  18.         return res
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement