Longest Substring Without Repeating Characters - Leetcode 3 - Python

preview_player
Показать описание
How to solve leetcode #3 - Longest Substring Without Repeating Characters in Python.

0:00 - Intro
0:12 - conceptual solution
3:12 - code

#leetcode #leetcode3 #python
Рекомендации по теме
Комментарии
Автор

Thanks for watching!

class Solution:
def lengthOfLongestSubstring(self, s: str) -> int:
res, curSet = 0, set()

l = 0
for r in range(len(s)):
while s[r] in curSet:
curSet.remove(s[l])
l += 1

curSet.add(s[r])
res = max(r - l + 1, res)

return res

leetprep
welcome to shbcf.ru