(python)leetcode刷题笔记03 Longest Substring Without Repeating Characters
3. Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters.
Examples:
Given "abcabcbb", the answer is "abc", which the length is . Given "bbbbb", the answer is "b", with the length of . Given "pwwkew", the answer is "wke", with the length of . Note that the answer must be a substring, "pwke" is a subsequence and not a substring
ANSWER:
class Solution:
def lengthOfLongestSubstring(self, s):
"""
:type s: str
:rtype: int
"""
if s:
i=
max_sub =s[]
len_s=len(s)
while i<len(s):
j=i+
for index in range(j,len_s):
if s[index] not in s[i:index]:
if len(s[i:index+])>len(max_sub):
max_sub=s[i:index+]
else:
break
i+=
return len(max_sub)
else:
return
code
def main(s):
if s:
i=
max_sub =s[]
len_s=len(s)
while i<len(s):
j=i+
for index in range(j,len_s):
if s[index] not in s[i:index]:
if len(s[i:index+])>len(max_sub):
max_sub=s[i:index+]
else:
break
i+=
return len(max_sub)
else:
return
if __name__ == '__main__':
s='pwwke'
print(main(s))
调试代码
(python)leetcode刷题笔记03 Longest Substring Without Repeating Characters的更多相关文章
- 【leetcode刷题笔记】Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters. For example, ...
- (python)leetcode刷题笔记05 Longest Palindromic Substring
5. Longest Palindromic Substring Given a string s, find the longest palindromic substring in s. You ...
- LeetCode(2) || Add Two Numbers && Longest Substring Without Repeating Characters
LeetCode(2) || Add Two Numbers && Longest Substring Without Repeating Characters 题记 刷LeetCod ...
- LeetCode解题笔记 - 3. Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters. Examples: Giv ...
- LeetCode第[3]题(Java):Longest Substring Without Repeating Characters 标签:Linked List
题目中文:没有重复字符的最长子串 题目难度:Medium 题目内容: Given a string, find the length of the longest substring without ...
- leetcode笔记:Longest Substring Without Repeating Characters
一. 题目描写叙述 Given a string, find the length of the longest substring without repeating characters. For ...
- leetcode-【中等题】3. Longest Substring Without Repeating Characters
题目: Given a string, find the length of the longest substring without repeating characters. Examples: ...
- 【Leetcode】【Medium】Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters. For example, ...
- 【leetcode刷题笔记】Longest Valid Parentheses
Given a string containing just the characters '(' and ')', find the length of the longest valid (wel ...
随机推荐
- HTTP协议之URL
1.什么是URL URL的全称是Uniform Resoure Locator,统一资源定位器.URL是浏览器寻找信息时所需的资源位置.当一个人将浏览器指向一个URL,浏览器就会在幕后发送适当的协议报 ...
- 【JSOI2008】最大数
https://www.luogu.org/problem/show?pid=1198 之前刚学完Splay想找题练手的时候做的,写完Splay交上去了才发现这应该是线段树裸题23333 Splay解 ...
- 异步编程Async/await关键字
异步编程Async \await 关键字在各编程语言中的发展(出现)纪实. 时间 语言版本 2012.08.15 C#5.0(VS2012) 2015.09.13 Python 3.5 2016.03 ...
- mongoDB之数据库操作
mongoDB中的数据库操作 查看数据库名称: db 查看所有数据库: show dbs 切换数据库: use 数据库名称 注意:如果数据库不存在,则指向数据库,但不会创建.直到插入数据或者是创建集合 ...
- Java-----SSM(SpringMVC+Spring+mybaties)框架整合
在进行整合之前,首先了解这个框架的作用 Mybaties: 丰富的标签库,可写动态sql,并统一的在.XML文件中编写,方便统一管理,解耦 SpringMVC: 标准的MVC思想(mode,view, ...
- nginx防恶意域名解析
今天无意间查看访问日志发现一个fhxywh.com的域名居然解析到了我的服务器,也就是说通过这个域名也能访问我的博客,这个就是赤裸裸的恶意域名解析了. 这个危害非常大,不仅会影响用户,而且不利于SEO ...
- (转)rabbitMQ基础知识及命令语句
摘要: 整理rabbitmq的用户管理相关知识,备忘 安装最新版本的rabbitmq(3.3.1),并启用management plugin后,使用默认的账号guest登陆管理控制台,却提示登陆失败. ...
- jvm系列(十一):JVM演讲PPT分享
JVM PPT的演进文稿分享 此PPT长达46页,不方便在页面中全部展示,文中只展示了文稿的前十二页. 获取完整版请在公众号内回复"JVM".
- C#相关知识总结
字符串相关知识 判断某字符串中包含某个字符,并过滤 if (string.Contains("*")) string = string.Replace('*',' '); // ...
- spring boot部署系统--morphling简介
Morphling 简介 Morphling是一套基于Spring Boot 1.5开发的部署系统,依赖简单,一套Mysql即可运行,操作简单明了,适用于百台规模几下机器的运维操作 功能概述 系统部署 ...