数据结构与算法:求字符串最大不重复子串

a=input()
max_count=[]
def zichuan(input_a):
    count=[]
    for i in input_a:
        if i not in count:
            count.append(i)
        else:
            input_a=input_a[1:]
            max_count.append(''.join(count))
            zichuan(input_a)
            return
    max_count.append(''.join(count))
    return 
zichuan(a)
m=list(map(len,max_count))
n=m.index(max(m))
the_max=max_count[n]
print(max_count,the_max,n,max(m))

输入:a12ac16
输出为
['a12', '12ac', '2ac16'] 2ac16  2 5
输入:
aabbccddefghbbb
输出:
['a', 'ab', 'b', 'bc', 'c', 'cd', 'd', 'defghb', 'efghb', 'fghb', 'ghb', 'hb', 'b', 'b', 'b'] defghb 7 6

#

总结:
1.迭代方法下面一定要立马接上return 否则进入迭代的前期参数会保留对后面产生影响
2.使用迭代与for遍历方法结合时 return一般会使用两次  返回遍历完成的结果
3.map函数要加list () ,且注意为()
补充 :list(map(lambda x, y: x + y, [1, 3, 5, 7, 9], [2, 4, 6, 8, 10]))
4.索引位置用index  注意为列表索引元素为list[]
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值