Longest Substring Without Repeating Characters

Posted 你瞅啥

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Longest Substring Without Repeating Characters相关的知识,希望对你有一定的参考价值。

题目如下:

Python代码:

class Solution(object):
    def lengthOfLongestSubstring(self, s):
        """
        :type s: str
        :rtype: int
        """
        string = []
        length = 0
        max = 0
        for i in range(len(s)):
            if s[i] not in string:
                string.append(s[i])
            else:
                pos = string.index(s[i])
                if pos<len(string)-1:
                    string = string[string.index(s[i])+1:]
                else:
                    string = []
                string.append(s[i])
            if len(string)>max:
                max = len(string)
        return max

 

以上是关于Longest Substring Without Repeating Characters的主要内容,如果未能解决你的问题,请参考以下文章

3. Longest Substring Without Repeating Characters

Leetcode-Longest Substring Without Repeating Characters

[LeetCode] Longest Substring Without Repeating Characters

Longest Substring Without Repeating Characters

Leetcode 3. Longest Substring Without Repeating Characters

leetcode: Longest Substring Without Repeating Characters