# Longest Substring Without Repeating Characters

{% embed url="<https://leetcode.com/problems/longest-substring-without-repeating-characters/>" %}

## Solution 1

```go
func lengthOfLongestSubstring(s string) int {
    var bitSet [256]bool
    res, left, right := 0, 0, 0
    for left < len(s) {
        if right >= len(s) {
            break
        }
        if bitSet[s[right]] {
            bitSet[s[left]] = false
            left++
        } else {
            bitSet[s[right]] = true
            right++
        }
        if right - left > res {
            res = right - left
        }
    }
    return res
}
```

We use a BitSet to mark if a single character is repeated or not.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://blog.yushunchen.com/algo/string/longest-substring-without-repeating-characters.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
