Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is 3. For "bbbbb" the longest substring is "b", with the length of 1.
def lengthOfLongestSubstring(S): res = '' temp = '' for i in range(len(S)): if S[i] not in temp: temp += S[i] else: if len(temp) > len(res): res = temp temp = temp[temp.index(S[i]) + 1:] + S[i] return res print lengthOfLongestSubstring("aacsdcsdvsdvngfjh")
本文介绍了一种寻找字符串中最长无重复字符子串的算法实现。通过遍历字符串并利用临时变量记录不重复的子串,该算法能有效地找出最长的无重复字符子串及其长度。
113

被折叠的 条评论
为什么被折叠?



