Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Longest Substring of Unique Characters by mortonfox
def uniq(s):
seen = set()
for c in s:
if c in seen: break
seen.add(c)
return len(seen)
def longest_substr(s: str) -> int:
return max((uniq(s[i:]) for i in range(len(s))), default=0)
print("Example:")
print(longest_substr("abcabcbb"))
# These "asserts" are used for self-checking
assert longest_substr("abcabcbb") == 3
assert longest_substr("bbbbb") == 1
assert longest_substr("pwwkew") == 3
assert longest_substr("abcdef") == 6
assert longest_substr("") == 0
assert longest_substr("au") == 2
assert longest_substr("dvdf") == 3
print("The mission is done! Click 'Check Solution' to earn rewards!")
Oct. 11, 2023