3. 无重复字符的最长子串
程序员文章站
2022-03-11 13:32:21
...
题目描述请点击查看LeetCode 题目描述
Python3 代码解答如下:
class Solution:
def lengthOfLongestSubstring(self, s):
"""
:type s: str
:rtype: int
"""
if s == "":
return 0
a_len = 1
for i in range(0, len(s)):
a = s[i]
for j in range(i+1, len(s)):
if a.find(s[j]) == -1:
a = s[i:j+1]
else:
break
if len(a) > a_len:
a_len = len(a)
print(a_len)
return a_len