LeetCode Google[01]: Longest Substring Without Repeating Characters

class Solution:
    def lengthOfLongestSubstring(self, s: str) -> int:
        # outlier
        if s == "":
            return 0
        if len(s) == 1:
            return 1
        max_i = 0
        start = 0
        end = 1
        limit = int(len(s))
        while end < limit:
            if s[end] not in s[start:end]:
                end += 1
                if end - start > max_i:
                    max_i = end - start
            else:
                start = s[start:end].index(s[end]) + 1 + start
        return max_i
        

猜你喜欢

转载自www.cnblogs.com/lywangjapan/p/12428069.html