Longest Substring Without Repeating Characters
unknown
python
17 days ago
1.0 kB
1
Indexable
Never
class Solution(object): def lengthOfLongestSubstring(self, s): """ :type s: str :rtype: int """ indexMap = {} l = 0 border1 = 0 border2 = 0 index = 0 result = 0 for char in s: if indexMap.get(char) is None: l += 1 result = max(l , result) indexMap[char] = index print(indexMap[char]) border2 = index else : if indexMap.get(char) < border1: l += 1 result = max(l , result) indexMap[char] = index border2 = index else : border1 = indexMap.get(char) + 1 border2 = index l = border2 - border1 + 1 result = max(l , result) indexMap[char] = index index += 1 return result
Leave a Comment