---
# System prepended metadata

title: 3. Longest Substring Without Repeating Characters

---

# 3. Longest Substring Without Repeating Characters

## Description
Given a string s, find the length of the longest substring without repeating characters.

## Solution

- Step1

```python=
class Solution:
    def lengthOfLongestSubstring(self, s: str) -> int:
        lis = []
        ans = 0
        for i in s:
            if i in lis:
                lis = lis[lis.index(i)+1:]
                
            lis.append(i)
            ans = max(ans, len(lis))

        return ans

```
## Discription
Traverse the whloe string, adding element into substring. When finding duplicated charactor, substring restarting from its next element.(sliding window)
## Complxity
Time complexity : O(N)
    
    
    