leetcode python 003
## 给定一个字符串,求其最长无重复的子字符串
##给定“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的更多相关文章
- Leetcode Python Solution(continue update)
leetcode python solution 1. two sum (easy) Given an array of integers, return indices of the two num ...
- Leetcode:003 无重复字符串
Leetcode:003 无重复字符串 关键点:给定一个字符串,请你找出其中不含有重复字符的 最长子串 的长度.示例 1:输入: "abcabcbb"输出: 3 解释: 因为无重复 ...
- LeetCode python实现题解(持续更新)
目录 LeetCode Python实现算法简介 0001 两数之和 0002 两数相加 0003 无重复字符的最长子串 0004 寻找两个有序数组的中位数 0005 最长回文子串 0006 Z字型变 ...
- [LeetCode][Python]Container With Most Water
# -*- coding: utf8 -*-'''https://oj.leetcode.com/problems/container-with-most-water/ Given n non-neg ...
- LeetCode Python 位操作 1
Python 位操作: 按位与 &, 按位或 | 体会不到 按位异或 ^ num ^ num = 0 左移 << num << 1 == num * 2**1 右移 & ...
- 【leetcode❤python】Sum Of Two Number
#-*- coding: UTF-8 -*- #既然不能使用加法和减法,那么就用位操作.下面以计算5+4的例子说明如何用位操作实现加法:#1. 用二进制表示两个加数,a=5=0101,b=4=0100 ...
- [Leetcode][Python]56: Merge Intervals
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 56: Merge Intervalshttps://oj.leetcode. ...
- [Leetcode][Python]55: Jump Game
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 55: Jump Gamehttps://leetcode.com/probl ...
- [Leetcode][Python]54: Spiral Matrix
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 54: Spiral Matrixhttps://leetcode.com/p ...
随机推荐
- 卡方分布 | t检验 | F检验 | 卡方检验 | 假设检验 | 各种检验持续总结
Chi-square distribution introduction 这个视频真的好,完美地解释了卡方统计量是怎么来的! 我们有一个标准正态分布的总体,我们从其中抽一次,取该值的平方就是Q1统计量 ...
- MP4介绍与基本AVC编码(x264)教程
MP4介绍与基本AVC编码(x264)教程(最后更新: 2006.03.25)为日益增加的对MP4 H264/AVC编码的需求,本人做了一个简单的MP4介绍与基本AVC编码(使用x264)教程最后更新 ...
- 20171022xlVBA练手提取入所记录
Sub GetWordText改进() Dim Wb As Workbook Dim Sht As Worksheet Dim Rng As Range Dim wdApp As Object Dim ...
- 2 爬虫 requests模块
requests模块 Requests是用python语言基于urllib编写的,采用的是Apache2 Licensed开源协议的HTTP库,Requests它会比urllib更加方便,reques ...
- P2375 [NOI2014]动物园
考虑kmp. 这个题的主要问题就在于怎样使复杂度是正确的O(n). 可以先预处理一个数组cnt[]表示不考虑不能相交这个限制,有多少个border. 这个东西其实也就是fail树上的深度. 然后考虑怎 ...
- sqlserver用timestamp帮助解决数据并发冲突 转【转】
http://blog.csdn.net/u011014032/article/details/42936783 关于并发请求,网上很多朋友都说的很详细了,我就不在这里献丑了.这里只记录下刚刚完工的那 ...
- java调用url
1 try { String str; URL u = new URL("https://www.baidu.com"); InputStream is = u.openStrea ...
- Mybatis中tinyint(1)数据自动转化为boolean处理
问题描述:使用Mybatis查询tinyint(1)字段数据,返回值为Map类型,那么tinyint(1)的数据默认会转化为boolean类型数据.解决方案: 1.使用ifnull(column, ...
- [CodeForces - 197B] B - Limit
B - Limit You are given two polynomials: P(x) = a0·xn + a1·xn - 1 + ... + an - 1·x + an and Q(x) = b ...
- Mysql for Linux安装配置之—— rpm(bundle)安装
1.准备及安装1)下载rpm安装包(或rpm bundle) rpm安装包包括两个(bundle会更多),一个是client,另一个是server,例如:MySQL-client-5.5.44-1. ...