[leetcode]无重复字符的最长子串
2018-08-28 21:48
429 查看
给定一个字符串,找出不含有重复字符的最长子串的长度。
示例 1:
示例 2:
示例 3:
请注意,答案必须是一个子串,
示例 1:
输入: "abcabcbb" 输出: 3 解释: 无重复字符的最长子串是 [code=plain]"abc",其长度为 3。[/code]
示例 2:
输入: "bbbbb" 输出: 1 解释: 无重复字符的最长子串是 [code=plain]"b",其长度为 1。[/code]
示例 3:
输入: "pwwkew" 输出: 3 解释: 无重复字符的最长子串是 [code=plain]"wke",其长度为 3。
请注意,答案必须是一个子串,
"pwke"是一个子序列 而不是子串。[/code]
class Solution(object): def lengthOfLongestSubstring(self, s): """ :type s: str :rtype: int """ s_len = len(s) max_len = 0 for i in range(0, s_len): count = 0 tmp_str = "" for j in s[i:]: if j not in tmp_str: tmp_str += j count += 1 if count > max_len: max_len = count else: break return max_len
相关文章推荐
- LeetCode题库解答与分析——#3.无重复字符的最长子串LongestSubstringWithoutRepeatingCharacters
- leetcode-最长无重复字符的子串
- LeetCode 3. 无重复字符的最长子串
- [LeetCode] Longest Substring Without Repeating Characters 无重复字符的最长子串
- LeetCode: 3_Longest Substring Without Repeating Characters | 求没有重复字符的最长子串的长度 | Medium
- Leetcode 刷题(python)之 无重复字符的最长子串
- 【LeetCode】3.无重复字符的最长子串 结题报告 (C++)
- [LeetCode]3. Longest Substring Without Repeating Characters寻找最长无重复字符的子串
- LeetCode-3:Longest Substring Without Repeating Characters (最长无重复字符的子串) --medium
- LeetCode - 无重复字符的最长子串
- leetcode:Longest Substring Without Repeating Characters (寻找最长无重复字符的子串)
- 【leetcode】第3题:求最长不重复(字符不重复)的子串的长度
- Leetcode 3. 无重复字符的最长子串
- [leetcode]获取字符串中字符不重复的最长子串的长度
- [leetcode]Longest Substring Without Repeating Characters【最长不重复字符子串】
- 【LeetCode题目记录-3】字符串中最长的没有重复字符的子串
- LeetCode 3. Longest Substring Without Repeating Characters--不包含重复字符的最长子串长度
- 求字符串中最长无重复字符的子串
- LintCode:M-最长无重复字符的子串
- 没有重复字符的最长子串