[leetcode] Longest Substring Without Repeating Characters

原创 2015年07月06日 21:02:34

Q: Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for “abcabcbb” is “abc”, which the length is 3. For “bbbbb” the longest substring is “b”, with the length of 1.

解题思路:动态规划

class Solution:
    # @param {string} s
    # @return {integer}
     def lengthOfLongestSubstring(self, s):
        if s is None or len(s)==0:
            return 0
        if len(s)==1:
            return 1
        dic = {}
        maxcount,startindex = 0,-1
        for index,i in enumerate(s):
            if i in dic and startindex<dic[i]:
                startindex = dic[i]
            if index-startindex>maxcount:
                maxcount = index-startindex
            dic[i]=index
        return maxcount

LeetCode Algorithms 3. Longest Substring Without Repeating Characters 题解

题目: Given a string, find the length of the longest substring without repeating characters.

《LeetBook》leetcode题解(3):Longest Substring Without Repeating Characters[M]——哈希判断重复

003. Longest Substring Without Repeating Characters[M]题目:Given a string, find the length of the long...

LeetCode 3. Longest Substring Without Repeating Characters--不包含重复字符的最长子串长度

Given a string, find the length of the longest substring without repeating characters. Examples: Giv...

[Leetcode #3]Longest Substring Without Repeating Characters 无重复字符的最长子串

原题地址:https://leetcode.com/problems/longest-substring-without-repeating-characters/ 题目要求是:给定一个字符串,找出...

leetcode之Longest Substring Without Repeating Characters

如题,这里的字符串不止是

LeetCode之3_Longest Substring Without Repeating Characters

题目原文:   Given a string, find the length of the longest substring without repeating characters. For...

Leetcode || Longest Substring Without Repeating Characters

Given a string, find the length of the longest substring without repeating characters. For example, ...

【LeetCode OJ 003】Longest Substring Without Repeating Characters

题目链接:https://leetcode.com/problems/longest-substring-without-repeating-characters/ 题目:Given a str...

[LeetCode]003-Longest Substring Without Repeating Characters

题目: Given a string, find the length of the longest substring without repeating characters. For exam...

Leetcode 3. Longest Substring Without Repeating Characters The Solution of Python and Javascript

Given a string, find the length of the longest substring without repeating characters.Examples:Given...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:[leetcode] Longest Substring Without Repeating Characters
举报原因:
原因补充:

(最多只允许输入30个字)