未验证 提交 9265f39b 编写于 作者: B BruceCat 提交者: GitHub

【3. 无重复字符的最长子串】【Python3】

【3. 无重复字符的最长子串】【Python3】
......@@ -371,4 +371,31 @@ class Solution:
<img src="../pictures/qrcode.jpg" width=200 >
</p>
======其他语言代码======
\ No newline at end of file
======其他语言代码======
第3题 Python3 代码(提供: [FaDrYL](https://github.com/FaDrYL) ):
```Python3
def lengthOfLongestSubstring(self, s: str) -> int:
# 子字符串
sub = ""
largest = 0
# 循环字符串,将当前字符加入子字符串,并检查长度
for i in range(len(s)):
if s[i] not in sub:
# 当前字符不存在于子字符串中,加入当前字符
sub += s[i]
else:
# 如果当前子字符串的长度超过了之前的记录
if len(sub) > largest:
largest = len(sub)
# 将子字符串从当前字符处+1切片至最后,并加入当前字符
sub = sub[sub.find(s[i])+1:] + s[i]
# 如果最后的子字符串长度超过了之前的记录
if len(sub) > largest:
return len(sub)
return largest
```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册