要求: Given a string, find the length of the longest substring without repeating characters. Examples: Given “abcabcbb”, the answer is “abc”, which the length is 3. Given “bbbbb”, the answer is “b”, with the length of 1. Given “pwwkew”, the answer is “wke”, with the length of 3. Note that the answer must be a substring, “pwke” is a subsequence and not a substring.
class Solution:
def lengthOfLongestSubstring3(self, s):
"""
:type s: str
:rtype: int
耗时139
"""
lens = 0
left = 0
right = 0
while right < len(s):
if not(s[right] in s[left:right]):
right += 1
else:
while s[left] != s[right]:
left += 1
left += 1
right += 1
if lens < right - left:
lens = right - left
return lens
leetCode之Longest Substring Without Repeating Characters实现
3 Longest Substring Without Repeating Characters要求: Given a string, find the length of the longest substring without repeating characters. Examples: Given “abcabcbb”, the answer is “abc”, which the