deflengthOfLongestSubstring(s:str)->int:"""
Calculates the length of the longest substring without repeating characters.
Args:
s (str): The input string.
Returns:
int: The length of the longest substring.
Examples:
>>> lengthOfLongestSubstring("abcabcbb")
3
>>> lengthOfLongestSubstring("bbbbb")
1
>>> lengthOfLongestSubstring("pwwkew")
3
"""max_index=len(s)-1start,end=0,0longest,substring=set(),set()whilestart<=max_indexandend<=max_index:character=s[end]ifcharacterinsubstring:substring=set()start+=1end=startelse:substring.add(character)end+=1longest=substringiflen(substring)>len(longest)elselongestreturnlen(longest)