easy/simple python3 solution using set


  • 0
    G

    easy/simple python3 solution using set.

    def length_of_longest_substring(s: str) -> int:
        length = maxlen = 0
        mm = set()
        for ch in s:
            if ch in mm:
                if maxlen < length:
                    maxlen = length
                length = 1
                mm.clear()
            else:
                length += 1
            mm.add(ch)
        return maxlen
    

Log in to reply
 

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