题解 | 双指针解法
最长不含重复字符的子字符串
http://www.nowcoder.com/practice/48d2ff79b8564c40a50fa79f9d5fa9c7
双指针解法 通过所有算例,耗时短,供参考
def lengthOfLongestSubstring(self , s: str) -> int:
cnt = 1
i = 0
k = 1
while i < len(s)-1 and k < len(s):
if s[k] not in s[i: k]:
cnt = max(cnt, len(s[i: k+1]))
k += 1
elif s[k] in s[i: k]:
i += 1
k = i+1
return cnt