Python easy solution with comment  90% O(n) speed & 98% space
\nclass Solution(object):\n    def lengthOfLongestSubstring(self, s):\n        seen = \'\'\n        mx = 0\n\t\t#1. for each character in s\n        for c in s:
```\nclass Solution(object):\n    def lengthOfLongestSubstring(self, s):\n        seen = \'\'\n        mx = 0\n\t\t#1. for each character in s\n        for c in s:\n\t\t\t#2. check if c is seen\n            if c not in seen:\n\t\t\t#3. if not seen, add to seen list \n                seen+=c\n            #4 if seen, slice seen list to previous c\n            # for example, if c is \'a\' and seen list is \'abc\'\n            # you will be slicing previous \'a\'(seen.index(c)+1), thus seen list become \'bc\'\n            # then add the current \'a\' bc + a, seenlist = \'bca\'\n            else:\n                seen = seen[seen.index(c) + 1:] + c\n            #5 check max length between current max with new length of seen\n            mx = max(mx, len(seen))\n        return mx\n```\n\nUpdate 09/11/21.\nAnother way of doing it. (not super fast but just for the record)\nusing left and right index with help of dictionary\n\n```\nclass Solution:\n    def lengthOfLongestSubstring(self, s: str) -> int:\n        seen = {}\n        mx = left = 0\n        #1. for each character in s\n        for right, c in enumerate(s):\n            #2. check if c is seen\n            if c in seen:\n                #3. if seen, advance left index\n                left = max(left, seen[c] + 1)\n            #4. regardless the character seen or not seen,\n            #   it will update the index of the charater.\n            seen[c] = right\n            #5. check max length between current left index and right index + 1\n            mx = max(mx, right-left+1)\n        return mx\n```\n\nw/o comments\n```\nclass Solution:\n    def lengthOfLongestSubstring(self, s: str) -> int:\n        seen = {}\n        mx = left = 0\n        for right, c in enumerate(s):\n            if c in seen:\n                left = max(left, seen[c] + 1)\n            seen[c] = right\n            mx = max(mx, right-left+1)\n        return mx\n\n```
['Python']