LeetCode 3. 无重复字符的最长子串 Python
2018-06-26 14:29
603 查看
给定一个字符串,找出不含有重复字符的最长子串的长度。示例:给定
阅读更多
"abcabcbb",没有重复字符的最长子串是
"abc",那么长度就是3。给定
"bbbbb",最长的子串就是
"b",长度是1。给定
"pwwkew",最长子串是
"wke",长度是3。请注意答案必须是一个子串,
"pwke"是 子序列 而不是子串。
class Solution(object): def lengthOfLongestSubstring(self, s): temp = res = "" for item in s:#对于字符串s中的每个字符 if item not in temp:#如果这个字符不在temp当中 temp += item if len(temp) > len(res): res = temp else: i = temp.index(item)#找到索引 if i == len(temp)-1: temp = item#如果到达末尾 else:temp = temp[i+1:] + item#没达到末尾 if len(temp) > len(res): res = temp return len(res)
阅读更多
相关文章推荐
- Leetcode 刷题(python)之 无重复字符的最长子串
- 【LeetCode】3.无重复字符的最长子串 结题报告 (C++)
- LeetCode 3. 无重复字符的最长子串
- Leetcode 3. 无重复字符的最长子串
- 无重复字符的最长子串 - LeetCode
- LeetCode: 3_Longest Substring Without Repeating Characters | 求没有重复字符的最长子串的长度 | Medium
- leetcode(三)—— Longest Substring Without Repeating Characters(最长不重复子串 Python/C++)
- [LeetCode] Longest Substring Without Repeating Characters 无重复字符的最长子串
- 【中级算法】3. 无重复字符的最长子串
- [LintCode 384] 最长无重复字符的子串(Python)
- LeetCode-3:Longest Substring Without Repeating Characters (最长无重复字符的子串) --medium
- LeetCode题库解答与分析——#3.无重复字符的最长子串LongestSubstringWithoutRepeatingCharacters
- LeetCode 3. Longest Substring Without Repeating Characters--不包含重复字符的最长子串长度
- LeetCode - 无重复字符的最长子串
- leetcode:Longest Substring Without Repeating Characters (寻找最长无重复字符的子串)
- 3. 无重复字符的最长子串
- 【leetcode】第3题:求最长不重复(字符不重复)的子串的长度
- leetcode(3)无重复字符的最长子串
- [leetcode]Longest Substring Without Repeating Characters【最长不重复字符子串】