mycode  99.21%

class Solution(object):
def lengthOfLongestSubstring(self, s):
"""
:type s: str
:rtype: int
"""
maxlen = 0
temp =''
for i in s:
if i not in temp:
temp += i
else:
maxlen = max(maxlen,len(temp))
temp = temp[temp.index(i)+1:] + i
maxlen = max(maxlen,len(temp))
return maxlen

注意:下面这种方式也可以及时更替最大长度

def lengthOfLongestSubstring(s):
l = 0
ls = ""
for i in s:
if i in ls:
ls = ls[ls.index(i)+1:]
ls += i
if len(ls) > l:
#maxres = max(maxres,len(ls))
l = len(ls)
return l
lengthOfLongestSubstring("abcdvdf")

  

leetcode-mid-array-3 Longest Substring Without Repeating Characters的更多相关文章

  1. LeetCode 第 3 题(Longest Substring Without Repeating Characters)

    LeetCode 第 3 题(Longest Substring Without Repeating Characters) Given a string, find the length of th ...

  2. Leetcode经典试题:Longest Substring Without Repeating Characters解析

    题目如下: Given a string, find the length of the longest substring without repeating characters. Example ...

  3. 【LeetCode】3 、Longest Substring Without Repeating Characters

    题目等级:Medium 题目描述:   Given a string, find the length of the longest substring without repeating chara ...

  4. leetcode第三题Longest Substring Without Repeating Characters java

    Longest Substring Without Repeating Characters Given a string, find the length of the longest substr ...

  5. leetcode第三题--Longest Substring Without Repeating Characters

    Problem:Given a string, find the length of the longest substring without repeating characters. For e ...

  6. LeetCode(3)Longest Substring Without Repeating Characters

    题目: Given a string, find the length of the longest substring without repeating characters. For examp ...

  7. LeetCode解题笔记 - 3. Longest Substring Without Repeating Characters

    Given a string, find the length of the longest substring without repeating characters. Examples: Giv ...

  8. LeetCode第三题—— Longest Substring Without Repeating Characters(最长无重复子字符串)

    题目描述 Given a string, find the length of the longest substring without repeating characters. Example ...

  9. LeetCode Hash Table 3. Longest Substring Without Repeating Characters

    HashMap的应用可以提高查找的速度,键key,值value的使用拜托了传统数组的遍历查找方式,对于判断一个字符或者字符串是否已经存在的问题可以非常好的解决.而本题需要解决的问题就是判断新遍历到的字 ...

  10. 【LeetCode算法题库】Day1:TwoSums & Add Two Numbers & Longest Substring Without Repeating Characters

    [Q1] Given an array of integers, return indices of the two numbers such that they add up to a specif ...

随机推荐

  1. 傻傻分不清?Integer、new Integer() 和 int 的面试题

    这篇有意思: 基本概念的区分: 1.Integer 是 int 的包装类,int 则是 java 的一种基本数据类型 2.Integer 变量必须实例化后才能使用,而int变量不需要 3.Intege ...

  2. [BZOJ 3930] [CQOI 2015]选数(莫比乌斯反演+杜教筛)

    [BZOJ 3930] [CQOI 2015]选数(莫比乌斯反演+杜教筛) 题面 我们知道,从区间\([L,R]\)(L和R为整数)中选取N个整数,总共有\((R-L+1)^N\)种方案.求最大公约数 ...

  3. PHP实现支付宝小程序用户授权的工具类

    背景 最近项目需要上线支付宝小程序,同时需要走用户的授权流程完成用户信息的存储,以前做过微信小程序的开发,本以为实现授权的过程是很简单的事情,但是再实现的过程中还是遇到了不少的坑,因此记录一下实现的过 ...

  4. html中的dl,dt,dd标签

    html <dl> <dt> <dd>是一组合标签,使用了dt dd最外层就必须使用dl包裹,此组合标签我们也又叫表格标签,与table表格类似组合标签,故名我们也 ...

  5. Java List对象集合按对象属性分组、分组汇总、过滤等操作示例

    import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.stream.Col ...

  6. Foundation框架下的常用类(NSNumber, NSValue, NSDate,NSDateFormatter)

    1.NSNumber 将基础数类型数据转成对象数据(比如int  float double BOOL  long等等) //通过NSNumber将基础数类型数据转成对象数据. NSNumber * i ...

  7. SSM框架返回json数据

    常见错误:No converter found for return value of type: class .................. 原因分析:这是因为springmvc默认是没有对象 ...

  8. jquery遍历标签中自定义的属性方法

    在开发中我们有时会对html标签添加属性,如何遍历处理 <ul> <li name="li1" sortid="nav_1">aaaaa ...

  9. makemap - 为sendmail创建数据库映像表

    SYNOPSIS(总览) [-N ] [-d ] [-f ] [-o ] [-r ] [-s ] [-v ] maptype mapname DESCRIPTION(描述) 创建 sendmail(8 ...

  10. CRMEasy知识库点击无法弹出窗体问题

    丢失控件   MSDATLST.OCX 将此控件放在路径下    C:\Windows\System32 并进行注册,具体方法为: 打开控件方式选择   C:\Windows\System32\reg ...