题目:https://leetcode.com/problems/longest-substring-without-repeating-characters/
简介:又是一推范围条件判断。。。
class Solution(object):
def lengthOfLongestSubstring(self, s):
"""
:type s: str
:rtype: int
"""
substring = ''
tmp_substring = ''
for index, sub_s in enumerate(s):
if index == 0:
tmp_substring = sub_s
elif sub_s not in tmp_substring:
tmp_substring += sub_s
elif sub_s in tmp_substring:
index_tmp = tmp_substring.index(sub_s)
if index_tmp != len(tmp_substring) - 1:
new_tmp_substring = tmp_substring[index_tmp+1:] + sub_s
if len(tmp_substring) >= len(substring):
substring = tmp_substring
tmp_substring = new_tmp_substring
else:
tmp_substring = new_tmp_substring
else:
new_tmp_substring = sub_s
if len(tmp_substring) >= len(substring):
substring = tmp_substring
tmp_substring = new_tmp_substring
else:
tmp_substring = new_tmp_substring
if len(tmp_substring) >= len(substring):
substring = tmp_substring
return len(substring)