Python solution with comments.
\n    def lengthOfLongestSubstring(self, s):\n        dic, res, start, = {}, 0, 0\n        for i, ch in enumerate(s):\n            if ch in dic:\n              
\n    def lengthOfLongestSubstring(self, s):\n        dic, res, start, = {}, 0, 0\n        for i, ch in enumerate(s):\n            if ch in dic:\n                res = max(res, i-start) # update the res\n                start = max(start, dic[ch]+1)  # here should be careful, like "abba"\n            dic[ch] = i\n        return max(res, len(s)-start)  # return should consider the last non-repeated substring
['Python']