# 题目

• 示例 1:

• 示例 2:

• 示例 3:

• 示例 4:

• 提示：

0 <= s.length <= 5 * 104
s 由英文字母、数字、符号和空格组成

# 解题

• 提交代码
``````class Solution:
def lengthOfLongestSubstring(self, s: str) -> int:
left = 0
right = 0
window = []
max = 0

while right < len(s):
window.append(s[right])
right+=1
#print("right: " + str(right) + "\tleft: " + str(left))
#print(window)
if (max < len(window)):
max = len(window)

while(right < len(s) and s[right] in window and left < right):
window.remove(window[0])
left += 1

return max
``````
• 本地测试代码
``````class Solution:
def lengthOfLongestSubstring(self, s: str) -> int:
left = 0
right = 0
window = []
max = 0

while right < len(s):
window.append(s[right])
right+=1

# print("right: " + str(right) + "\tleft: " + str(left))

print(window)

if (max < len(window)):
max = len(window)

while(right < len(s) and s[right] in window and left < right):
window.remove(window[0])
left += 1

return max

S = Solution()

length = S.lengthOfLongestSubstring("abcdda")

print("#########################")
print(length)
``````

### 要不赞赏一下?

 微信 支付宝 PayPal Bitcoin

``https://www.emperinter.info/2022/01/13/longest-substring-without-repeating-characters/``

## 优惠码

 阿里云国际版 20美元 Vultr 10美元 搬瓦工 | Bandwagon 应该有折扣吧？ Just My Socks JMS9272283 【注意手动复制去跳转】 域名 | namesilo `emperinter`(1美元) 币安 币安