class Solution(object):
def LengthOfLongestSubstring(self,s):
d = {}
start = 0
ans = 0
for i,c in enumerate(s):
if c in d:
start = max(start, d[c] + 1)
d[c] = i
ans = max(ans, i-start + 1)
return ans
if __name__ == '__main__':
s = 'pwwkew'
a = Solution()
res = a.LengthOfLongestSubstring(s)
print(res)