A python solution - 32ms


  • 0
    Y

    '''
    class Solution(object):
    def lengthOfLongestSubstring(self, s):
    """
    :type s: str
    :rtype: int
    """
    if len(set(s)) == len(s):
    return len(s)
    else:
    max = len(set(s))
    l = len(s)
    for i in range(max, 0,-1):
    for j in range(l - i + 1):
    tmp = s[j:j + i]
    if len(set(tmp)) == i:
    return i
    '''
    I am a new Python user. Could anybody optimize the code for me? Thanks a lot.


Log in to reply
 

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