LeetCode(python):3-无重复字符的最长子串

LeetCode(python):3-无重复字符的最长子串,第1张

LeetCode(python):3-无重复字符的最长子

给定一个字符串 s ,请你找出其中不含有重复字符的 最长子串 的长度

 

代码展示:

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

测试结果展示:

 

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5437023.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-12-11
下一篇2022-12-11

发表评论

登录后才能评论

评论列表(0条)

    保存