diff --git "a/\347\256\227\346\263\225\346\200\235\347\273\264\347\263\273\345\210\227/\346\273\221\345\212\250\347\252\227\345\217\243\346\212\200\345\267\247.md" "b/\347\256\227\346\263\225\346\200\235\347\273\264\347\263\273\345\210\227/\346\273\221\345\212\250\347\252\227\345\217\243\346\212\200\345\267\247.md" index 67e6539ca1fbb5dc1f7c7e3ac80d7a8c297c074c..e213979693c724bd2a58a93c31f2a47cad78fd2d 100644 --- "a/\347\256\227\346\263\225\346\200\235\347\273\264\347\263\273\345\210\227/\346\273\221\345\212\250\347\252\227\345\217\243\346\212\200\345\267\247.md" +++ "b/\347\256\227\346\263\225\346\200\235\347\273\264\347\263\273\345\210\227/\346\273\221\345\212\250\347\252\227\345\217\243\346\212\200\345\267\247.md" @@ -371,4 +371,31 @@ class Solution:

-======其他语言代码====== \ 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 +```