leetcode 3. Longest Substring Without Repeating Characters

题目描述

https://leetcode.com/problems/longest-substring-without-repeating-characters/

解决方法

一:

class Solution(object):
    def lengthOfLongestSubstring(self, s):
        """
        :type s: str
        :rtype: int
        """
        lens = len(set(s))
        i = 0
        if lens == 0:
            return 0
        
        while lens > 0:
            test_len = len(set(s[i:i+lens]))
            if  test_len == lens:
                return test_len
            elif i + lens > len(s) - 1:
                lens = lens -1
                i = 0
            else:
                i = i + 1
原文地址:https://www.cnblogs.com/sojrs/p/10981074.html