Clean python solution


  • 0
    class Solution(object):
        def lengthOfLongestSubstring(self, s):
            r, record, slow = 0, {}, 0
    
            for i, char in enumerate(s):
                if char not in record or record[char] < slow:
                    r = max(r, i - slow + 1)
                else:
                    slow = record[char] + 1
                record[char] = i
            return r

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.