请提供一段代码，实现在字符串中最长无重复字符子串的长度。请使用python语言，并以markdown形式输出代码。
user
```python
def length_of_longest_substring(s: str) -> int:
    char_map = {}
    left = 0
    max_length = 0
    
    for right in range(len(s)):
        if s[right] in char_map:
            left = max(left, char_map[s[right]] + 1)
        
        char_map[s[right]] = right
        max_length = max(max_length, right - left + 1)
    
    return max_length

# 示例用法
input_str = "abcabcbb"
print(length_of_longest_substring(input_str))  # 输出: 3
```
assistant