原题:

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. HTTP POST发消息

    业务需求:模拟TANX给DSP发消息,protobuf数据已弄好. 代码: def PostDataToDSP(self,url,postdata): headers = { #taobao文档规定 ...

  2. C、Shell、Perl基于Tomcat开发CGI程序环境配置

    基于Tomcat7.0版本号配置CGI开发环境,步聚例如以下: 以我的Tomcat7安装文件夹为例:TOMCA_HOME = /Users/yangxin/Documents/devToos/java ...

  3. java20 创建服务器:ServerSocket

    创建服务器:ServerSocket import java.io.BufferedReader; import java.io.IOException; import java.io.InputSt ...

  4. WSGI是一种编程接口,而uwsgi是一种传输协议

    http://uwsgi-docs.readthedocs.io/en/latest/Nginx.html http://sunxiunan.com/?p=1778 cgi---------fastc ...

  5. Awake和Start

    经过查阅资料和自己的理解整理出来的,欢迎大家指教. Awake和Start对比 awake比start先执行. 当有多个类的时候,所有类的awake执行完了才会执行start. awake里面一般放初 ...

  6. PPTP、L2TP、IPSec和SSLVPN的区别

    VPN (虚拟专用网)发展至今已经不在是一个单纯的经过加密的访问隧道了,它已经融合了访问控制.传输管理.加密.路由选择.可用性管理等多种功能,并在全球的信息安全体系中发挥着重要的作用.也在网络上,有关 ...

  7. javascript进击(七)Ajax

    AJAX AJAX = Asynchronous JavaScript and XML(异步的 JavaScript 和 XML). AJAX 不是新的编程语言,而是一种使用现有标准的新方法. AJA ...

  8. Linux Bash终端快捷键小结

    Ctrl + A  定位至行首 Ctrl + E  定位至行尾 Ctrl + U  向前删除至行首 Ctrl + K  向后删除至行尾 Ctrl + L  清屏

  9. O-C相关-10-动态类型检查

    10-动态类型检查 1.动态绑定 1)OC 中方法的调用不由编译器决定,而由运行时决定 2)OC 中没有方法调用,只有消息接收. 一般称消息为选择器 2.动态类型检查 对象在运行时获得类型的能力称为内 ...

  10. libCURL动态分配buffer——节约内存

    libCURL是一个免费的.开源的强大客户端url传输库.支持的平台.协议甚广.平台上有Windows.Linux.FreeBSD:协议上有FTP.HTTP(S).Telnet.DICT.File等. ...