Longest Substring Without Repeating Characters
Total Accepted: 23252 Total Submissions: 104165 My SubmissionsGiven 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.
class Solution:
# @return an integer
def lengthOfLongestSubstring(self, s):
res = 0
subStr = ''
slow = 0
for fast in range(len(s)):
if s[fast] not in subStr:
subStr += s[fast]
else :
res = max(res, len(subStr))
while s[slow] != s[fast] : slow += 1
slow += 1
subStr = s[slow : fast+1]
res = max(res, len(subStr))
return res
本文介绍了一种寻找字符串中最长无重复字符子串的方法。通过双指针技术实现高效遍历,找到符合条件的最长子串长度。示例中使用Python实现,并提供了具体代码。
981

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



