首页 > 其他 > 详细

leetcode 3. Longest Substring Without Repeating Characters

时间:2019-06-05 18:20:28      阅读:68      评论:0      收藏:0      [点我收藏+]

题目描述

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 3. Longest Substring Without Repeating Characters

原文:https://www.cnblogs.com/sojrs/p/10981074.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!