[本文出自天外归云的博客园]
我的思路:
class Solution(object): def lengthOfLongestSubstring(self, s): """ :type s: str :rtype: int """ longtest_length = 0 length_s = len(s) for i in range(length_s): sub = [] j = i while j < length_s and s[j] not in sub: sub.append(s[j]) j = j + 1 sub_length = len(sub) if sub_length > longtest_length: longtest_length = sub_length return longtest_length