leet code 003:Longest Substring Without Repeating Characters

来源:互联网 发布:学校网络下载不了 编辑:程序博客网 时间:2024/06/16 03:52

题目描述:

Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is 3. For "bbbbb" the longest substring is "b", with the length of 1.

题目大意:

给定一个字符串,从中找出不含重复字符的最长子串的长度。例如,"abcabcbb"的不含重复字母的最长子串为"abc",其长度是3。"bbbbb"的最长子串是"b",长度为1。

解题思路:

按顺序拾取未出现过的字符

Python代码:

def find_diff(n):    l=len(n)    st=''    for i in range(l):        if n[i] not in st:            st+=n[i]    l=len(st)    print('The string "'+n+'" without repeating letters is "'+st+'" , and the lenth is '+str(l))str001=input('Please input some strings:')find_diff(str001)


阅读全文
0 0