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
上一篇:LeetCode练题——122. Best Time to Buy and Sell Stock II


下一篇:388. Longest Absolute File Path