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的更多相关文章

  1. 【leetcode刷题笔记】Longest Substring Without Repeating Characters

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

  2. (python)leetcode刷题笔记05 Longest Palindromic Substring

    5. Longest Palindromic Substring Given a string s, find the longest palindromic substring in s. You ...

  3. LeetCode(2) || Add Two Numbers && Longest Substring Without Repeating Characters

    LeetCode(2) || Add Two Numbers && Longest Substring Without Repeating Characters 题记 刷LeetCod ...

  4. LeetCode解题笔记 - 3. Longest Substring Without Repeating Characters

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

  5. LeetCode第[3]题(Java):Longest Substring Without Repeating Characters 标签:Linked List

    题目中文:没有重复字符的最长子串 题目难度:Medium 题目内容: Given a string, find the length of the longest substring without ...

  6. leetcode笔记:Longest Substring Without Repeating Characters

    一. 题目描写叙述 Given a string, find the length of the longest substring without repeating characters. For ...

  7. leetcode-【中等题】3. Longest Substring Without Repeating Characters

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

  8. 【Leetcode】【Medium】Longest Substring Without Repeating Characters

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

  9. 【leetcode刷题笔记】Longest Valid Parentheses

    Given a string containing just the characters '(' and ')', find the length of the longest valid (wel ...

随机推荐

  1. git操作之上传gitthub

    push 失败解决方法: 分支操作: 分支操作之覆盖: 主master操作:

  2. mysql基础知识点

    /* 启动MySQL */net start mysql /* 连接与断开服务器 */mysql -h 地址 -P 端口 -u 用户名 -p 密码 /* 跳过权限验证登录MySQL */mysqld ...

  3. pymysql实现MySQL与Python交互

    常见MySQL操作 所需模块: pip3 install pymysql 查询(fetchone,fetchmany,fetchall): import pymysql #连接 con = pymys ...

  4. 在Github上面搭建一个自己域名的Hexo博客

    前言 在一次看到别人的博客主页,觉得设计很漂亮.但是由于自己对于前台这块没什么办法,煞是羡慕.偶然中发现这种样式是在Github上面搭建的,使用的是Next主题.于是便想自己也搭建一个,于是便去就去查 ...

  5. Netty之二进制文件传输

    传输会话简要 客户端发起一个文本请求给服务器端, 服务器端解析里面文本, 返回文件给客户端, 客户端解析文件 服务器端 因为示例文件比较小, 所以没有做分段传输, 而是直接一次性把整个文件byte[] ...

  6. 班级博客客户端Beta阶段发布说明

    班级博客客户端Beta阶段发布说明 NewTeam 2017/12/18 项目 博客园班级博客Android客户端 目录 发布方式和发布地址 新功能 修复的缺陷 对运行环境的要求 安装方法 已知的问题 ...

  7. SqlParameter 用法总结

    作用 解决恶意的T-sql语句攻击第一种 //传入参数 string ProductGroupCode, string Ismaintain, int HierarchyID, string BOMN ...

  8. 自己手写WEB程序框架并执行

    1.新建目录,起名MyWeb 2.目录下,新建两个目录 WEB-INF, META-INF,,还能够新建一些jsp,html文件 ,如 index.html 3在WEB-INF中必须存在一个文件WEB ...

  9. 前端笔记——如何控制表单控件中的disabled

    0.前言     本文主要说明如何使能或禁止表单控件.表单控件具有disabled属性,通过设置该属性可以禁止所有的input控件,input的更多属性请参考资料[1].下面就通过一个简单的例子说明如 ...

  10. 十六、Spring Boot 部署与服务配置

    spring Boot 其默认是集成web容器的,启动方式由像普通Java程序一样,main函数入口启动.其内置Tomcat容器或Jetty容器,具体由配置来决定(默认Tomcat).当然你也可以将项 ...