码迷,mamicode.com
首页 > 其他好文 > 详细

LeetCode Google[01]: Longest Substring Without Repeating Characters

时间:2020-03-06 20:22:22      阅读:56      评论:0      收藏:0      [点我收藏+]

标签:char   turn   else   sel   start   while   out   max   end   

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
        

LeetCode Google[01]: Longest Substring Without Repeating Characters

标签:char   turn   else   sel   start   while   out   max   end   

原文地址:https://www.cnblogs.com/lywangjapan/p/12428069.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!