Leetcode 解题 Longest Substring without repeating charcater python
原题:
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的更多相关文章
- C++版- Leetcode 3. Longest Substring Without Repeating Characters解题报告
Leetcode 3. Longest Substring Without Repeating Characters 提交网址: https://leetcode.com/problems/longe ...
- LeetCode 3 Longest Substring Without Repeating Characters 解题报告
LeetCode 第3题3 Longest Substring Without Repeating Characters 首先我们看题目要求: Given a string, find the len ...
- [LeetCode] 3. Longest Substring Without Repeating Characters 解题思路
Given a string, find the length of the longest substring without repeating characters. For example, ...
- 【LeetCode】Longest Substring Without Repeating Characters 解题报告
[题意] Given a string, find the length of the longest substring without repeating characters. For exam ...
- LeetCode 3 Longest Substring Without Repeating Characters(最长不重复子序列)
题目来源:https://leetcode.com/problems/longest-substring-without-repeating-characters/ Given a string, f ...
- [Leetcode Week1]Longest Substring Without Repeating Characters
Longest Substring Without Repeating Characters题解 原创文章,拒绝转载 题目来源:https://leetcode.com/problems/longes ...
- [LeetCode] 3.Longest Substring Without Repeating Characters 最长无重复子串
Given a string, find the length of the longest substring without repeating characters. Example 1: In ...
- 【leetcode】Longest Substring Without Repeating Characters
题目描述: Given a string, find the length of the longest substring without repeating characters. For exa ...
- Leetcode3:Longest Substring Without Repeating Characters@Python
Given a string, find the length of the longest substring without repeating characters. Examples: Giv ...
随机推荐
- 【转】Java Thread.join()详解
http://www.open-open.com/lib/view/open1371741636171.html 一.使用方式. join是Thread类的一个方法,启动线程后直接调用,例如: ? 1 ...
- POJ 1330 Nearest Common Ancestors(Tree)
题目:Nearest Common Ancestors 根据输入建立树,然后求2个结点的最近共同祖先. 注意几点: (1)记录每个结点的父亲,比较层级时要用: (2)记录层级: (3)记录每个结点的孩 ...
- Android网络传输中必用的两个加密算法:MD5 和 RSA (附java完毕測试代码)
MD5和RSA是网络传输中最经常使用的两个算法,了解这两个算法原理后就能大致知道加密是怎么一回事了.但这两种算法使用环境有差异,刚好互补. 一.MD5算法 首先MD5是不可逆的,仅仅能加密而不能解密. ...
- LINUX系统镜像下载总汇
LINUX系统fedora.centos.debian.ubuntu ISO下载汇总 http://mirrors.sohu.com http://linux.ilvgo.cn/ ftp://gent ...
- Linux系列:Ubuntu虚拟机设置固定IP上网(配置IP、网关、DNS、防止resolv.conf被重写)
虚拟机里设置上网方式为NAT最方便,因为无需手动设置即可上网,但是NAT的上网方式默认是DHCP动态分配IP的,这意味着你每次重启虚拟机都 有不一样的IP地址,这对一般用户没任何问题.但是如果你的机子 ...
- 简洁 Abstract Factory模式(3.1)
镇楼 在某些书中使用了二维图说明抽象工厂模式.非常好,可是yqj2065不喜欢他们的产品族/产品等级,改成品牌/产品类型. 抽象工厂模式(abstract factory pattern)较工厂方法模 ...
- 【转】windows环境下利用doxygen生成代码文档
作者:jiangwenna http://www.jiangwenna.com/windows-doxygen-doc/ Doxygen是一种开源跨平台的,以类似JavaDoc风格描述的文档系统 ...
- Linux NFS 说明,配置及故障分析
一.NFS服务简介 NFS 是Network File System的缩写,即网络文件系统.一种使用于分散式文件系统的协定,由Sun公司开发,于1984年向外公布.功能是通过网络让不同的机器.不同的操 ...
- Add an IPv6 route through an interface
Not often needed, sometimes in cases of dedicated point-to-point links. 7.4.1. Using "ip" ...
- javaHDU1003Max Sum
import java.util.Scanner; public class Sum {public static void main(String args[]) {Scanner cin=n ...