## 给定一个字符串,求其最长无重复的子字符串
##给定“abcabcbb”,答案是“abc”,长度为3。
##给定“bbbbb”,答案是“b”,长度为1。
##鉴于“pwwkew”,答案是“wke”,长度为3。
import time
import random
import string
x,l=1000,[]
for i in range(x):
    l.append(''.join(random.sample(string.ascii_letters + string.digits,1)))
s=''.join(l)
t=time.time()
q,ll,l='',[],0
for i in s:
    if q.find(i)<0:
        q='%s%s'%(q,i)
    else:
        if len(q)>=l:
            ll.append(q)
            l=len(q)
        q=('%s%s'%(q,i))[q.find(i)+1:]
lll=[]
for i in ll:
    if len(i)==l:
        lll.append(i)
t=time.time()-t
print('%s 元素用时 %s s'%(x,t))
print(lll,l)

leetcode python 003的更多相关文章

  1. Leetcode Python Solution(continue update)

    leetcode python solution 1. two sum (easy) Given an array of integers, return indices of the two num ...

  2. Leetcode:003 无重复字符串

    Leetcode:003 无重复字符串 关键点:给定一个字符串,请你找出其中不含有重复字符的 最长子串 的长度.示例 1:输入: "abcabcbb"输出: 3 解释: 因为无重复 ...

  3. LeetCode python实现题解(持续更新)

    目录 LeetCode Python实现算法简介 0001 两数之和 0002 两数相加 0003 无重复字符的最长子串 0004 寻找两个有序数组的中位数 0005 最长回文子串 0006 Z字型变 ...

  4. [LeetCode][Python]Container With Most Water

    # -*- coding: utf8 -*-'''https://oj.leetcode.com/problems/container-with-most-water/ Given n non-neg ...

  5. LeetCode Python 位操作 1

    Python 位操作: 按位与 &, 按位或 | 体会不到 按位异或 ^ num ^ num = 0 左移 << num << 1 == num * 2**1 右移 & ...

  6. 【leetcode❤python】Sum Of Two Number

    #-*- coding: UTF-8 -*- #既然不能使用加法和减法,那么就用位操作.下面以计算5+4的例子说明如何用位操作实现加法:#1. 用二进制表示两个加数,a=5=0101,b=4=0100 ...

  7. [Leetcode][Python]56: Merge Intervals

    # -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 56: Merge Intervalshttps://oj.leetcode. ...

  8. [Leetcode][Python]55: Jump Game

    # -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 55: Jump Gamehttps://leetcode.com/probl ...

  9. [Leetcode][Python]54: Spiral Matrix

    # -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 54: Spiral Matrixhttps://leetcode.com/p ...

随机推荐

  1. English trip V1 - B 6.Where Are You From? Teacher:Patrick Key: 一般疑问句和否定句中的be动词

    In this lesson you will learn to talk about countries and languages.  本节课你将学习到关于谈论城市和语言 课上内容(Lesson) ...

  2. LeetCode--290--单词模式

    问题描述: 给定一种 pattern(模式) 和一个字符串 str ,判断 str 是否遵循相同的模式. 这里的遵循指完全匹配,例如, pattern 里的每个字母和字符串 str 中的每个非空单词之 ...

  3. wdcp环境安装filephp扩展

    网址 :https://blog.csdn.net/m_nanle_xiaobudiu/article/details/80838424

  4. Sticks HDU - 1455 (未完成)

    George took sticks of the same length and cut them randomly until all parts became at most 50 units ...

  5. ubuntu下安装CAJ阅读器

    目录 1.ubuntu下wine的基本介绍 (1)wine的介绍 (2)wine的安装 (3)exe文件的安装 (4)exe程序的卸载 (6)wine的基本使用 2.CAJ阅读器的安装 (1)首先放上 ...

  6. Spring boot(六)优雅使用mybatis

    orm框架的本质是简化编程中操作数据库的编码,发展到现在基本上就剩两家了,一个是宣称可以不用写一句SQL的hibernate,一个是可以灵活调试动态sql的mybatis,两者各有特点,在企业级系统开 ...

  7. 【Java】【3】BeanUtils.copyProperties();将一个实体类的值复制到另外一个实体类

    正文: a,b为对象 BeanUtils.copyProperties(a,  b); 1,BeanUtils是org.springframework.beans.BeanUtils, a拷贝到b 2 ...

  8. token原理详解

    概念与使用流程 是计算机术语:令牌,令牌是一种能够控制站点占有媒体的特殊帧,以区别数据帧及其他控制帧.token其实说的更通俗点可以叫暗号,在一些数据传输之前,要先进行暗号的核对,不同的暗号被授权不同 ...

  9. mongodb副本集修改配置问题

    因虚拟机地址被占用,需要重新设置ip地址,这时需要修改副本集中的IP地址配置: 1: 查看配置rs.config():需要找到primary主机,在该主节点服务器上才有权限修改配置 2:rs.remo ...

  10. JdbcTemplate查询返回JavaBean的几种方法

    关于JdbcTemplate的官方描述如下: org.springframework.jdbc.core.JdbcTemplate 大约的讲,将JdbcTemplate返回的list结果集生成Java ...