Skip to content

Commit 269b4d6

Browse files
Update LongestSubstringWithoutRepeatingCharacters.py
1 parent 934a5ef commit 269b4d6

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

Longest Substring Without Repeating Characters/LongestSubstringWithoutRepeatingCharacters.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,17 @@ def lengthOfLongestSubstring(self, s):
77
:rtype: int
88
"""
99

10-
temp_list = []
11-
max_length, length = 0, 0
10+
temp_list = [] # 存储子字符串
11+
max_length, length = 0, 0 # length跟踪子字符串的长度
1212

1313
for letter in s:
1414
if letter not in temp_list:
1515
length += 1
1616
if length > max_length:
1717
max_length = length
1818
else:
19+
# 这里由于后边的字符的最大不重复子字符串不可能超过第一个
20+
# 所以要从第一个已经的不重复的字符开始计算
1921
temp_list = temp_list[temp_list.index(letter) + 1:]
2022
length = len(temp_list) + 1
2123
temp_list.append(letter)

0 commit comments

Comments
 (0)