Last active
March 20, 2024 04:30
-
-
Save syedsaqibali/e288fa754fb025bbf3e565203a981d6f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution: | |
def lengthOfLongestSubstring(self, s: str) -> int: | |
max_run_length = 0 | |
start_run_index = -1 | |
while start_run_index <= len(s) - max_run_length: | |
start_run_index += 1 | |
run_letters = set([]) if start_run_index == 0 else set(list(s[start_run_index:start_run_index+max_run_length])) | |
if len(run_letters) < max_run_length: | |
continue | |
for k in s[start_run_index+max_run_length:]: | |
if k in run_letters: | |
break | |
run_letters.add(k) | |
max_run_length += 1 | |
return max_run_length |
jkamashian
commented
Mar 20, 2024
@jkamashian yours is a lot more clever than mine!
@syedsaqibali but you have no idea how long this took me 🤣
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment