# # # @param s string字符串 # @return int整型 # from collections import defaultdict class Solution: def lengthOfLongestSubstring(self , s ): # write code herekm window = dict.fromkeys(s, 0) left = 0 right = 0 res = 0 while right < len(s): c = s[right] right += 1 window[c] += 1 while window[c]>1: d = s[left] left += 1 window[d] -= 1 res = max(res, right-left) return res