leetcode--寻找连续最大不重复子串

def find_max_substr(astring):
    max_sub_str, temp = [], []
    left_ptr, right_ptr = 0, 0
    total = len(astring)
    while right_ptr < total:
        cur_str = astring[right_ptr]
        if cur_str not in temp:
            temp.append(cur_str)
            right_ptr += 1
        else:
            if len(temp) > len(max_sub_str):
                max_sub_str = temp
            index = temp.index(cur_str)
            left_ptr = left_ptr+index+1
            temp = [astring[j] for j in range(left_ptr, right_ptr)]

    if len(temp) > len(max_sub_str):
        max_sub_str = temp

    return max_sub_str

astring = 'asdfabcefghijk'
ret = find_max_substr(astring)
print(''.join(ret), len(ret))

 

上一篇:洛谷——P1151 子数整数


下一篇:tensorflow 多计算图并行(使用mp多进程)