标签:block logs ati 之间 题目 elf log 索引 while
题目描述:求一个字符串的不含重复字符的最长连续子串的长度;
感觉这是个动态规划题,暂时没用动态规划分析,后续再说。
class Solution(object):
def lengthOfLongestSubstring(self, s):
"""
:type s: str
:rtype: int
"""
hashes = {}
left, right, length = 0, 0, len(s)
max_len = 0
while right < length:
if hashes.get(s[right]) and hashes[s[right]] >= left:
left = hashes[s[right]]
hashes[s[right]] = right + 1
max_len = max(max_len, right - left + 1)
right += 1
return max_len
Python 解leetcode:3. Longest Substring Without Repeating Characters
标签:block logs ati 之间 题目 elf log 索引 while
原文地址:http://www.cnblogs.com/qiaojushuang/p/8001492.html