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. P1177快速排序

    这是一个快速排序的模板题.拿到题后便写了quicksort(确定一个基准数,利用两个哨兵,把大的放右边,小的放左边,再递归实现排序),但是竟然TLE了60pts(???),于是翻看dalao们的题解, ...

  2. qtreewidget 显示保存xml文件

    此文是读取和存储已知结构的xml,对于未知结构的xml,可以用递归方法读取和遍历.可参考文章:Qt遍历不规则树的节点. 1.QTreewidget设置 //折叠图标(三角图标)换成自定义图标 ui-& ...

  3. 【JZOJ 3918】蛋糕

    题面: 正文: 根据数据\(4\leq R,C\leq 75\)我们大概可以先枚举切横的刀再二分答案. 更具体的: 假设我们已经枚举到这样横切: 再假设我们已经二分到最小的巧克力是\(7\) 康康第一 ...

  4. zprofiler工具

    转自:zprofiler三板斧解决cpu占用率过高问题 此工具为阿里自产的profiler工具,在其他文章中看到有用此工具进行性能问题定位的.在此转载文章学习一下. 上周五碰到了一个线上机器cpu占用 ...

  5. Vue切换页面时中断axios请求

    一.概述 在Vue单页面开发过程中,遇到这样的情况,当我切换页面时,由于上一页面请求执行时间长,切换到该页面时,还未执行完,这时那个请求仍会继续执行直到请求结束,此时将会影响页面性能,并且可能对现在页 ...

  6. linux基本命令之磁盘管理命令(ls,cd,pwd,mkdir,rmdir,clear, touch)

    linux磁盘管理命令 1.ls(list)命令:列出目录内容. 格式:ls [参数][文件或目录] ls -a或-all表示列出所有文件和目录,以点开始的是影藏文件,例如,.bash_history ...

  7. python Rabbitmq编程(一)

    python Rabbitmq编程(一) 实现最简单的队列通信 send端 #!/usr/bin/env python import pika credentials = pika.PlainCred ...

  8. __bridge

    Core Foundation 框架Core Foundation框架 (CoreFoundation.framework) 是一组C语言接口,它们为iOS应用程序提供基本数据管理和服务功能.下面列举 ...

  9. fastadmin 搭建到云虚拟主机

    1.把public下的index.php.router.php.install.php.admin_*******.php..htaccess(伪静态文件),移到  文件夹:/htdocs   根目录 ...

  10. 〇——什么是SHELL

    在这段时间里中我们了解一下SHELL编程. 什么是shell shell是Linux的命令解释器,用于解释用户对操作系统的操作. 用shell解释的Linux命令有很多,可以通过cat/etc/she ...