Finish problem 0003-longest-substring-without-repeating-characters

This commit is contained in:
Johan Sandoval
2026-07-22 12:17:30 -05:00
parent def79644a1
commit 07b0eab7aa
2 changed files with 25 additions and 0 deletions
@@ -0,0 +1,11 @@
class Solution:
def lengthOfLongestSubstring(self, s: str) -> int:
hash = {}
longest = 0
start = 0
for idx, char in enumerate(s):
if char in hash and hash[char] >= start:
start = hash[char] + 1
hash[char] = idx
longest = max(longest, idx - start + 1)
return longest