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