class Solution(object):
    def lengthOfLongestSubstring(self, s):
        """
        :type s: str
        :rtype: int
        """
        dq = collections.deque()
        charSet = set()
        maxLen = 0
        for c in s:
            if c in charSet:
                while True:
                    leftMostChar = dq.popleft()
                    charSet.remove(leftMostChar)
                    if leftMostChar == c:
                        break
            charSet.add(c)
            dq.append(c)
            maxLen = len(dq) if maxLen < len(dq) else maxLen
        return maxLen

@@ -137,64 +137,30 @@
     
-dq = collections.deque()%0A        charSet = set()
+lastOccur = %7B%7D
 %0A       
  max
@@ -151,24 +151,27 @@
 = %7B%7D%0A       
+ j,
  maxLen = 0%0A
@@ -167,16 +167,19 @@
 maxLen =
+ 0,
  0%0A     
@@ -188,15 +188,29 @@
  for
+ i,
  c in 
-s
+enumerate(s)
 :%0A  
@@ -231,326 +231,136 @@
  in 
-charSet:%0A                while True:%0A                    leftMostChar = dq.popleft()%0A                    charSet.remove(leftMostChar)%0A                    if leftMostChar == c:%0A                        break%0A            charSet.add(c)%0A            dq.append(c)%0A            maxLen = len(dq) if maxLen %3C len(dq) else maxLen
+lastOccur:%0A                j = max(j, lastOccur%5Bc%5D + 1)%0A            lastOccur%5Bc%5D = i%0A            maxLen = max(maxLen, i - j + 1)
 %0A   

Update solution.py