Share my solution


  • 0
    N
    class Solution(object):
    def lengthOfLongestSubstring(self, s):
        """
        :type s: str
        :rtype: int
        """
        length = len(s)
        max_len = 0
        i, j, loc1, loc2 = 0, 0, 0, 0
        
        while i < length:
            j = loc1
            while j < i:
                if s[j] == s[i]:
                    if i - loc1 > max_len:
                        max_len = i - loc1
                    loc1 = j + 1
                j += 1
            i += 1
        if i - loc1 > max_len:
            max_len = i - loc1
        return max_len

Log in to reply
 

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