常见面试题:一个字符串中找出其最长并且没有重复字符的子字符串

a = '1233rdffdf324241324sdfdsf934543jdsf'
num = 0
char = ''
a_list = list(a)
for i in a_list:
    for x in a_list[a_list.index(i)+1:]:
        i += x
        set_len = len(set(i))
        str_len = len(i)
        if set_len == str_len:
            if set_len > num:
                num = set_len
                char = i
print char,num

你可能感兴趣的:(常见面试题:一个字符串中找出其最长并且没有重复字符的子字符串)