My Python answer


  • 0
    A
    class Solution(object):
        def lengthOfLongestSubstring(self, s):
            """
            :type s: str
            :rtype: int
            """
            resultCount = 0
            temp = ""
            for c in s:
                if c in temp:
                    if resultCount < len(temp):
                        resultCount = len(temp)
                    temp = temp[temp.find(c) + 1:] + c
                else:
                    temp += c
            return len(temp) if len(temp) > resultCount else resultCount
    

Log in to reply
 

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