class Solution:
def lengthOfLongestSubstring(self, s):
if s is None and len(s) == 0:
return 0
letter_last_pos = dict()
origin_list = list(s)
letter_list = []
i, j = 0, 0
len_max = 0
cur = 0
while i <= j and j < len(s):
if s[j] not in letter_list:
# letter last pos update
letter_last_pos[s[j]] = j
# update letter_list without repeat letters
letter_list = origin_list[i:j+1]
cur = len(letter_list)
else:
# move i to proper pos to make sure there is no repeat letter
# between [i, j]
i = letter_last_pos[s[j]] + 1
del letter_list[:]
# update letter_list without repeat letters
letter_list = origin_list[i:j+1]
# letter last pos update
letter_last_pos[s[j]] = j
cur = len(letter_list)
len_max = max(cur, len_max)
j += 1
return len_max