原题:

Given a string, find the length of the longest substring without repeating character

For example, the Longest substring without repeating letters for "abcabcbb" is "abc", with the length is 3

思路:参考blog.csdn.net/hcbbt/article/details/43966513

开一个数组记录当前字符最近出现的位置,遍历,更新左边界,用它计算最大值。

代码:

class Solution:
def lenthOfLongestSubstring(self, s):
res = 0
left = 0
d = {} for i , ch in enumerate(s):
if ch in d and d[ch] >= left: left = d[ch] + 1
d[ch] = i
res = max(res, i -left + 1)
return res

Leetcode 解题 Longest Substring without repeating charcater python的更多相关文章

  1. C++版- Leetcode 3. Longest Substring Without Repeating Characters解题报告

    Leetcode 3. Longest Substring Without Repeating Characters 提交网址: https://leetcode.com/problems/longe ...

  2. LeetCode 3 Longest Substring Without Repeating Characters 解题报告

    LeetCode 第3题3 Longest Substring Without Repeating Characters 首先我们看题目要求: Given a string, find the len ...

  3. [LeetCode] 3. Longest Substring Without Repeating Characters 解题思路

    Given a string, find the length of the longest substring without repeating characters. For example, ...

  4. 【LeetCode】Longest Substring Without Repeating Characters 解题报告

    [题意] Given a string, find the length of the longest substring without repeating characters. For exam ...

  5. LeetCode 3 Longest Substring Without Repeating Characters(最长不重复子序列)

    题目来源:https://leetcode.com/problems/longest-substring-without-repeating-characters/ Given a string, f ...

  6. [Leetcode Week1]Longest Substring Without Repeating Characters

    Longest Substring Without Repeating Characters题解 原创文章,拒绝转载 题目来源:https://leetcode.com/problems/longes ...

  7. [LeetCode] 3.Longest Substring Without Repeating Characters 最长无重复子串

    Given a string, find the length of the longest substring without repeating characters. Example 1: In ...

  8. 【leetcode】Longest Substring Without Repeating Characters

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

  9. Leetcode3:Longest Substring Without Repeating Characters@Python

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

随机推荐

  1. 如何停止IIS

    当一台计算机同时安装了IIS服务器和apache服务器的时候,需要运行其中的一个服务器就需要将另一个服务器停止,那么如何停止IIS服务器: 双击[world wide web publishing s ...

  2. 《编程导论(Java)·2.1.3改写(override)》

    <编程导论(Java)·2.1.3改写(override)>,收集override内容. 方法改写(method overriding)是指对于父类定义的一个实例方法,同意子类提供自己的实 ...

  3. Codeforces 439D Devu and his Brother 三分

    题目链接:点击打开链接 = - =曾经的三分姿势不对竟然没有被卡掉,,,太逗.. #include<iostream> #include<string> #include< ...

  4. WPF制作QQ列表(仿qq列表特效)

    先看效果图:这个是折叠特效. 代码结构:      model是我们的数据模型,定义了在列表显示的人物名称   图片   简介    . Resource是我们的图片资源  和 存储图片资源路径.名称 ...

  5. Java 字节数组类型(byte[])与int类型互转

    代码如下: public class CommonUtils { //高位在前,低位在后 public static byte[] int2bytes(int num){ byte[] result ...

  6. 组合模式(Composite Pattern)

    组合模式定义:组合模式允许你将对象组合成树形结构来表现"整体/局部"层次结构,组合能让客户以一致的方式处理个别对象以及对象组合. 当涉及到如:菜单,子菜单之类的问题时,会自然而然的 ...

  7. (转)CSS行高——line-height

    原文地址:http://www.cnblogs.com/dolphinX/p/3236686.html 初入前端的时候觉得CSS知道display.position.float就可以在布局上游刃有余了 ...

  8. eclipse修改SVN下载的项目“>”变成“*”

    遇到过这样的问题,可能是因为下载的eclipse 的版本国过于高的原因. 一张图说明就行了. 将红色的地方打上勾就行了.

  9. JS七种加密解密方法

    http://www.cnblogs.com/mq0036/p/4983858.html HTML或JS加密解密 本文一共介绍了七种方法:   一:最简单的加密解密   二:转义字符"\&q ...

  10. Power Map 更新日志

    2015-05-18,五月更新 Custom Regions feature,允许用户自定义区域要素,支持kml和shape格式 New customization features,包括图例/文本框 ...